I have a table as shown in this figure:
The LaTeX code for the table is:
\begin{table}
\begin{tabular}{ | c | c | }
\hline
\includegraphics[scale=0.45]{../0_1.eps} & 1.10 2.20 3.30 4.40 \\
\hline
\end{tabular}
\end{table}
I would like to make the four numbers appear in different lines inside the second cell, in order to reduce its width. I wonder how to do it?
EDIT:
I tried \linebreak,
\includegraphics[scale=0.45]{../0_1.eps} & 1.10 \linebreak 2.20 \linebreak 3.30 \linebreak 4.40 \\
But the result is the same as before i.e. without \linebreak.
EDIT:
I just tried what Rob suggested. But the result is not compact, because my intention is to reduce the size of the table. See the figure below:
Try using a p column with \par to indicate line breaks.
\begin{table}
\begin{tabular}{ | c | p{2cm} | }
\hline
\includegraphics[scale=0.45]{../0_1.eps} & 1.10\par 2.20\par 3.30\par 4.40 \\
\hline
\end{tabular}
\end{table}
Try
\begin{table}
\def\baselinestretch {}\selectfont %
% \baselineskip = 14.4pt\relax %% Uncomment this if the result is not compact.
\begin{tabular}{ | c | p{2cm} | }
\hline
$\vcenter{\hbox{\includegraphics[scale=0.45]{../0_1.eps}}$ &
$\vcenter{\strut 1.10\par 2.20\par 3.30\par 4.40\strut}$ \\
\hline
\end{tabular}
\end{table}
You can use mathmode in the last cell: ${1.10 \atop 2.20 } \atop {3.30 \atop 4.40}$.
That will be nice and small...
If you want it bigger, cf. Typesetting fraction terms to be larger in an equation.
I would look into using the multirow package. Details on spanning multiple columns/rows are here.
\linebreak ? sometimes works for me in tables and sometimes doesn't.
Minipage might accomplish this.
\begin{minipage}{3in}
% escape the weirdness of tabular with your own mini page
1.10 \\ 2.20 \\ 3.30 \\ 4.40
\end{minipage}
You may also want a \strut on the first and last lines, to prevent it abutting any tabular borders.
Related
I have a table I wish to fit in the margins. I also wish to add both EPS and PPS above the middle of the cells with these two in. I am not sure why adding a caption is not working either. Here is the code:
\begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|p{3cm}| }
\multicolumn{5}{c}{} \\
\hline
&EPS:Pre &EPS:Post &PPS:Pre & PPS:Post \\
\hline
Species tested:&13 &15& 43& 43\\
Compounds tested:& 745 & 745& 310& 361 \\
Unique tests:& 193& 193& 406& 407\\
Total experiments:&17,811 &17,929& 107,470& 130,926\\
\hline
\end{tabular}
\label{tab}
Thank you.
There where several problems.
Your table was too large, with the margins and intercolumn spacing. I made a macro to fine adjust column width.
To redefine a column (for instance to center a header), you can use `\multicolumn{1}{c}{header}
\label assigns a number that is used in a numbered environment. It is associated with the table environmenent, not with tabular. The label appears within a caption. Also, the table is centered within the table environment.
\documentclass{article}
\begin{document}
\newcommand{\colwidth}{0.17\textwidth}
\newcommand{\centercolumn}[1]{\multicolumn{1}{c|}{#1}}
\begin{table}
\centering
\begin{tabular}{ |p{3cm}||p{\colwidth}|p{\colwidth}|p{\colwidth}|p{\colwidth}| }
% \multicolumn{5}{c}{} \\ useless, I think
\hline
&\centercolumn{EPS:Pre} &\centercolumn{EPS:Post} &\centercolumn{PPS:Pre} & \centercolumn{PPS:Post} \\
\hline
Species tested:&13 &15& 43& 43\\
Compounds tested:& 745 & 745& 310& 361 \\
Unique tests:& 193& 193& 406& 407\\
Total experiments:&17,811 &17,929& 107,470& 130,926\\
\hline
\end{tabular}
\caption{My table}
\label{tab:1}
\end{table}
\end{document}
I am trying to center one of the columns in a table and It says I have an extra column. The table also doesnt look correct i.e.
What it looks like:
F(t) F(s)
u(t)
1/s
e 1/(s-a)
What I expect:
F(t) F(s)
u(t) 1/s
e 1/(s-a)
I think it is because I'm trying to insert an equation in the table but I'm not sure.
Here is the code
\documentclass[12pt, letterpaper, fleqn]{article}
\usepackage{array}
\begin{document}
\begin{table}
% \setlength{\tabcolsep}{6pt}
% \renewcommand{\arraystretch}{1}
\begin{tabular}{p{0.225\textwidth} >{\centering}p{0.15\textwidth}}
\textbf{F(t)} & \textbf{F(s)} \\
\(u(t)\) & \(\frac{1}{s}\) \\
\(e^{at}\) & \(\frac{1}{s-a}\) \\
\end{tabular}
\end{table}
\end{document}
Your use of \centering to centre the column works, but it screws up the way \\ is interpreted. A correction is included in the array package documentation after using alignment switches (like \centering, \raggedright, \raggedleft, etc) using \arraybackslash:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{ p{0.225\textwidth} >{\centering\arraybackslash}p{0.15\textwidth} }
$\mathbf{F(t)}$ & $\mathbf{F(s)}$ \\
$u(t)$ & $1 / s$ \\
$e^{at}$ & $1 / (s - a)$
\end{tabular}
\end{document}
If you remove >{\centering}, then your code should compile as expected. Post a comment otherwise! Do you want any column to have centered contents?
In the output below, I'm trying to align Author with the top of the box next to it. I've tried a couple of different boxes and whatnot, but I can't get it to align properly.
Here's the code:
\mbox{
Author
}
\fbox{\begin{minipage}[c]{12cm}
\medskip
$for(author)$
$author.name$\\$if(author.title)$\emph{$author.title$}\\$endif$$if(author.company)$$author.company$$endif$
\par\medskip
$endfor$
\medskip
\end{minipage}}
You should set the entire construction inside a tabular, and then also use a [t]op-aligned tabular for the framed box construction:
\documentclass{article}
\begin{document}
\begin{tabular}{l | l |}
\cline{2-2}
Author & \begin{tabular}[t]{#{}p{12cm}#{}}
Jack Appleseed \\
\emph{Marketing Manager} \\
Unimaginitive Solutions \\ \\
John Appleseed \\
\emph{Business Development Manager} \\
Unimaginitive Solutions \\
\end{tabular} \\
\cline{2-2}
\end{tabular}
\end{document}
I'm assuming you can use the following Pandoc construction (I haven't used Pandoc):
\begin{tabular}{l | l |}
\cline{2-2}
Author & \begin{tabular}[t]{#{}p{12cm}#{}}
$for(author)$
$author.name$ \\ $if(author.title)$\emph{$author.title$} \\ $endif$ $if(author.company)$ $author.company$ \\ $endif$
$endfor$
\end{tabular} \\
\cline{2-2}
\end{tabular}
Ok so i wrote this simple code (shown below) to create an alternate colour table using \rowcolors, yet instead of just colouring the rows of the table it colours the whole row (even more than textwidth). Any help how to fix this?
begin{table}[ht]
\scriptsize
\begin{center}
\rowcolors{1}{lightgray}{white}
\caption{...}
\begin{tabular}{p{0.45\textwidth} | p{0.55\textwidth}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F \\
\end{tabular}
\end{center}
\end{table}
While 0.45\textwidth + 0.55\textwidth would seem to fit within \textwidth, each of your p-columns have an extra column separation... on both sides. To that end, you should remove them in order to make it fit within the text block boundary:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{lipsum}
\begin{document}
\begin{table}[ht]
\scriptsize\centering
\rowcolors{1}{lightgray}{white}
\caption{This is a table.}
\begin{tabular}{
p{\dimexpr0.45\textwidth-2\tabcolsep} |
p{\dimexpr0.55\textwidth-2\tabcolsep}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F
\end{tabular}
\end{table}
\lipsum[1]
\end{document}
Also, don't use the center environment; use \centering instead.
I know that if you define a width in a table's column, you can get automatic word-wrapping.
However, I need to control where newlines should happen in a specific table cell.
Thus, how can I insert manual line breaks in a LaTeX table cell?
Usually, you use a column definition like p{3cm} instead of l, and then use \newline instead of \\ in the cell body.
You could do it like this:
\documentclass{report}
\begin{document}
\begin{tabular}{|l|l|}
\hline
A & B \\
& C \\
\hline
D & E \\
\hline
\end{tabular}
\end{document}
which produces:
The command \shortstack can be used to wrap cell content and use \\ inside it:
\begin{tabular}{|l|l|}
\hline
one line & \shortstack{two\\ lines} \\
\hline
XX & YYY \\
\hline
\end{tabular}
EDIT: however I just realised that interline spacing might differ between your columns. So it's not the prettiest solution.
It can be achieved by using \newline. Since, the accepted answer did not have any sample snippet, a working sample is provided here:
\begin{tabular}{p{2cm} p{10cm}}
\em{Programming} \textsc{languages} & Java, Node.js, Python, Clojure \\
\newline & \newline \\
\em{Development systems} & Concurrent Programming, Design Patterns
\end{tabular}
You can do like Bart suggested above and combine with multirow to centralize single line texts.
\begin{table}[h]
\centering
\caption{Optimized models (Softmax) final results with confidence intervals.}
\begin{tabular}{|c|c|c|c|c|}
\hline
\multirow{2}*{Architecture} & Batch & N. & Learning & \multirow{2}*{Micro-F1} \\
& size & epochs & rate & \\
\hline
ResNet50& 64 & 60 & $5\times10^{-3}$ & $(\textbf{0.7683} \pm 0.0223)$ \\
\hline
ResNet152\_V2& 64 & 40 & $5\times10^{-4}$ & $(0.6698 \pm 0.0467)$\\
\hline
\end{tabular}
\label{final_result_softmax}
\end{table}
Yields:
\newline works to break a line within a cell in tabularx environment.