Multicolumn in Latex - latex

I'm sorry if this question has been asked before, but I just canĀ“t figure out how to create this table, while keeping it somewhat nice looking.
I have attached an image, containing an Excel representation of the table I'm trying to create.
I hope a Latex master can help me out here!

Use \multicolumn{n-cells}{alignment}{content}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Outer Fold & \multicolumn{2}{c|}{ANN model} & \multicolumn{2}{c|}{Lin Reg model} & Baseline model \\
\hline
i & $h_i^*$ & $E_i^{test}$ & $L_i^*$ & $E_i^{test}$ & $E_i^{test}$ \\
\hline
1 & 3 & 0.301 & 128 & 1.206 & 1.219 \\
1 & 3 & 0.301 & 128 & 1.206 & 1.219 \\
1 & 3 & 0.301 & 128 & 1.206 & 1.219 \\
\hline
\end{tabular}

Related

What Seems to be the Problem With This LaTeX Code?

I am working with Stata to create a balance table for some data using the balancetable ado package. While I believe the balancetable commands are working, the output LaTeX document won't run the table that it is trying to print. Given that I am still learning how to use LaTeX, any assistance with trying to see what the syntax issue is with this LaTeX code would be much appreciated. I'm getting issues related to the document name, typesetting and compiler issues.
\begin{tabular}{l*{3}c}
\hline\hline
& (1) & (2) & (3) \\
\hline
agesq&677.315&717.395&40.079\\
&(428.784)&(431.252)&(41.341)\\
educ&10.088&10.346&0.257\\
&(1.614)&(2.011)&(0.172)\\
black&0.827&0.843&0.016\\
&(0.379)&(0.365)&(0.036)\\
hisp&0.108&0.059&-0.048*\\
&(0.311)&(0.237)&(0.027)\\
married&0.154&0.189&0.035\\
&(0.361)&(0.393)&(0.036)\\
nodegree&0.835&0.708&-0.127***\\
&(0.372)&(0.456)&(0.039)\\
mosinex&17.862&18.492&0.630\\
&(5.574)&(4.911)&(0.511)\\
re74&2.107&2.096&-0.011\\
&(5.688)&(4.887)&(0.516)\\
re75&1.267&1.532&0.265\\
&(3.103)&(3.219)&(0.303)\\
\hline
Observations & 260 & 185 & 445 \\
\hline\hline
\end{tabular}
```!LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 \begin{tabular}
{l*{3}c}
?```
In LaTeX, there's some lines you should always have. \documentclass{article} (doesn't have to be the article format). Afterwards, there is the document environment where your tabular environment would be in. This would look like:
\documentclass{article}
\begin{document}
\begin{tabular}{l*{3}c}
\hline\hline
& (1) & (2) & (3) \\ \hline
agesq & 677.315 & 717.395 & 40.079 \\
& (428.784) & (431.252) & (41.341) \\
educ & 10.088 & 10.346 & 0.257 \\
& (1.614) & (2.011) & (0.172) \\
black & 0.827 & 0.843 & 0.016 \\
& (0.379) & (0.365) & (0.036) \\
hisp & 0.108 & 0.059 & -0.048* \\
& (0.311) & (0.237) & (0.027) \\
married & 0.154 & 0.189 & 0.035 \\
& (0.361) & (0.393) & (0.036) \\
nodegree& 0.835 & 0.708 & -0.127*** \\
& (0.372) & (0.456) & (0.039) \\
mosinex & 17.862 & 18.492 & 0.630 \\
& (5.574) & (4.911) & (0.511) \\
re74 & 2.107 & 2.096 & -0.011 \\
& (5.688) & (4.887) & (0.516) \\
re75 & 1.267 & 1.532 & 0.265 \\
& (3.103) & (3.219) & (0.303) \\
\hline
Observations & 260 & 185 & 445 \\
\hline\hline
\end{tabular}
\end{document}
Indentations and spacing aren't required but they do make the document more understandable for the writer. Here's what this document generates:

Errors in Latex I can't fix Involving Multi-Row and Mulit-Column Issues [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
\begin{center}
\footnotesize
\begin{tabular}{| c | c c c |}
\hline
\multirow{3}{*}{Equipment acquired at start of year} & \multicolumn{3}{c|}{Replacement cost (\$) for given years} & &\\
\cline{2-4}
& 1 & 2 & 3\\
\hline
1 & 4000 & \multicolumn{1}{|c|}{5400} & 9800\\
2 & 4300 & \multicolumn{1}{|c|}{6200} & 8700\\
3 & 4800 & \multicolumn{1}{|c|}{7100} & -\\
4 & 4900 & \multicolumn{1}{|c|}{-} & -\\
\hline
\end{tabular}
\end{center}
im getting an error:
Extra alignment tab has been changed to \cr.
Also for this portion of code I'm not sure what exactly is the error (I'm getting like 20 misplaced errors and missing brackets):
\begin{table}[]
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{11}{Directed Edge Weights (Row $\rightarrow$ Col)} & & & & & & & & & & \\
\hline
$\rightarrow$ & A & B & C & D & E & F & G & H & I & J\\
\hline
A&0&4000&&&&&&&&\\
B&&0&5400&4300&&&&&&\\
C&&&0&&9800&6200&4800&&&\\
D&&&&0&9800&6200&4800&&&\\
E&&&&&0&&&8700&7100&4900\\
F&&&&&&0&&8700&7100&4900\\
G&&&&&&&0&8700&7100&4900\\
H&&&&&&&&0&&\\
I&&&&&&&&&0&\\
J&&&&&&&&&&0\\
\hline
\end{tabular}
\caption{Table of Adjacent Edges}
\label{tab:Edges of graph}
\end{table}
please help :)
In both cases it appears that there are additional cells added after your use of multicolumn. In the first case you can remove & & after the multicolumn and all should work fine:
\begin{center}
\footnotesize
\begin{tabular}{| c | c c c |}
\hline
\multirow{3}{*}{Equipment acquired at start of year} & \multicolumn{3}{c|}{Replacement cost (\$) for given years} \\
\cline{2-4}
& 1 & 2 & 3\\
\hline
1 & 4000 & \multicolumn{1}{|c|}{5400} & 9800\\
2 & 4300 & \multicolumn{1}{|c|}{6200} & 8700\\
3 & 4800 & \multicolumn{1}{|c|}{7100} & -\\
4 & 4900 & \multicolumn{1}{|c|}{-} & -\\
\hline
\end{tabular}
\end{center}
and in the second case you need to remove the repeated & symbols after multicolumn. Also in this case there is no indication of the spacing in multicolumn. The below table works fine for me, though I have added {c} in the multicolumn.
\begin{table}
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{11}{c}{Directed Edge Weights (Row $\rightarrow$ Col)} \\
\hline
$\rightarrow$ & A & B & C & D & E & F & G & H & I & J\\
\hline
A&0&4000&&&&&&&&\\
B&&0&5400&4300&&&&&&\\
C&&&0&&9800&6200&4800&&&\\
D&&&&0&9800&6200&4800&&&\\
E&&&&&0&&&8700&7100&4900\\
F&&&&&&0&&8700&7100&4900\\
G&&&&&&&0&8700&7100&4900\\
H&&&&&&&&0&&\\
I&&&&&&&&&0&\\
J&&&&&&&&&&0\\ \hline
\end{tabular}
\caption{Table of Adjacent Edges}
\label{tab:Edges of graph}
\end{table}

Latex minipage table alignment

I'm attempting to align two tables in Latex document to be next to each other. Although this is working, the positions of the tables are off. The first is located lower than the second:
Does anyone know how to fix this? Below is my code:
\begin{table}[t]
\begin{minipage}{.55\linewidth}
\begin{tabular}{l|l}
\multicolumn{1}{c|}{\textbf{WordNet}} & \textbf{FreeBase} \\ \hline
domain\_region & cause\_of\_death \\
domain\_topic & ethnicity \\
has\_instance & gender \\
has\_part & institution \\
member\_holonym & nationality \\
member\_meronym & profession \\
part\_of & religion \\
similar\_to & \\
subordinate\_instance\_of & \\
synset\_domain\_topic & \\
type\_of &
\end{tabular}
\label{table1}
\caption{Relationships in WordNet \& FreeBase KBs}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\begin{tabular}{cccc}
\multicolumn{4}{c}{\textbf{Holdout Set Construction}} \\
\multicolumn{2}{c}{\textbf{WordNet}} & \multicolumn{2}{c}{\textbf{FreeBase}} \\ \hline
Word Removed & \multicolumn{1}{c|}{\# Triples} & Name Removed & \# Triples \\
adult & \multicolumn{1}{c|}{166} & Alan Turing & 15 \\
botany & \multicolumn{1}{c|}{166} & Carl Sagan & 18 \\
building & \multicolumn{1}{c|}{185} & Frank Zappa & 16 \\
center & \multicolumn{1}{c|}{180} & Isaac Asimov & 20 \\
form & \multicolumn{1}{c|}{172} & John Denver & 16 \\
game & \multicolumn{1}{c|}{267} & Karl Marx & 13 \\
lake & \multicolumn{1}{c|}{227} & Mary Astor & 14 \\
land & \multicolumn{1}{c|}{153} & Su Song & 13 \\
mythology & \multicolumn{1}{c|}{178} & Tupac Shakur & 14 \\
room & \multicolumn{1}{c|}{189} & ... & ...
\end{tabular}
\caption{Ten words and a sample of 60 names used for constructing Holdout sets for WordNet and FreeBase, respectively. The numbers of triples that each entity occurs in are listed to the right. These triples comprise the Holdout sets}
\label{table2}
\end{minipage}
\end{table}
You can try setting the tabulars with the same content, even though some rows might be empty. This will ensure they have the same height:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[landscape]{geometry}% Just for this example
\usepackage{booktabs}
\begin{document}
\begin{table}
\mbox{}\hfill
\begin{minipage}[t]{.48\linewidth}
\centering{\ttfamily
\begin{tabular}{ l l }
\toprule
\\
\multicolumn{1}{ c }{\normalfont\bfseries WordNet} & \multicolumn{1}{ c }{\normalfont\bfseries FreeBase} \\
\midrule
domain\_region & cause\_of\_death \\
domain\_topic & ethnicity \\
has\_instance & gender \\
has\_part & institution \\
member\_holonym & nationality \\
member\_meronym & profession \\
part\_of & religion \\
similar\_to & \\
subordinate\_instance\_of & \\
synset\_domain\_topic & \\
type\_of & \\
\bottomrule
\end{tabular}}
\caption{Relationships in WordNet \& FreeBase KBs.}
\end{minipage}\hfill
\begin{minipage}[t]{.48\linewidth}
\centering
\begin{tabular}{ c c c c }
\toprule
\multicolumn{4}{c}{\bfseries Holdout Set Construction} \\
\multicolumn{2}{c}{\bfseries WordNet} & \multicolumn{2}{c}{\bfseries FreeBase} \\
\midrule
\itshape Word Removed & \itshape\# Triples & \itshape Name Removed & \itshape \# Triples \\
adult & 166 & Alan Turing & 15 \\
botany & 166 & Carl Sagan & 18 \\
building & 185 & Frank Zappa & 16 \\
center & 180 & Isaac Asimov & 20 \\
form & 172 & John Denver & 16 \\
game & 267 & Karl Marx & 13 \\
lake & 227 & Mary Astor & 14 \\
land & 153 & Su Song & 13 \\
mythology & 178 & Tupac Shakur & 14 \\
room & 189 & \ldots & \ldots \\
\bottomrule
\end{tabular}
\caption{Ten words and a sample of 60 names used for constructing Holdout sets for WordNet and FreeBase,
respectively. The numbers of triples that each entity occurs in are listed to the right.
These triples comprise the Holdout sets.}
\end{minipage}\hfill
\mbox{}
\end{table}
\end{document}
I've used
fontenc to produce a better \_ within the typewriter font (used in the left-hand table);
booktabs to provide better-looking tables.
\itshape to distinguish a sub-heading within the right-hand table from other content within the same table.

Latex Problem: Undefined control sequence when using /multirow

I simple want to combine some cells in a row of a table in Latex. For instance,
I tried to compile the following table:
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{3}{|c|}{Team sheet} \\
\hline
Goalkeeper & GK & Paul Robinson \\ \hline
\multirow{4}{*}{Defenders} & LB & Lucus Radebe \\
& DC & Michael Duberry \\
& DC & Dominic Matteo \\
& RB & Didier Domi \\ \hline
\multirow{3}{*}{Midfielders} & MC & David Batty \\
& MC & Eirik Bakke \\
& MC & Jody Morris \\ \hline
Forward & FW & Jamie McMaster \\ \hline
\multirow{2}{*}{Strikers} & ST & Alan Smith \\
& ST & Mark Viduka \\
\hline
\end{tabular}
Then I get the error:
! Undefined control sequence.
<recently read> \multirow
l.821 \multirow
Does anyone have an idea what I am doing wrong? Do I need a special package? Interestingly enough, the multicolumn command is working! Weird.
How about trying
\usepackage{multirow}
?
Multirow is not a defined command. This is because of the structure of tables in LaTeX: line by line. You can use the \cline command to make sure that horizontal lines between rows do not separate the first column, but the label "Defenders" would still be at the top of the cell.
It seems that the multirow package (which comes with the complete MikTeX distribution) addresses this issue.
See also:
Manual of the multirow package
Small tutorial on multirow
EDIT: You don't want to combine cells in a row, as you have wrote, but you want to combine cells in one column. Simply write empty cells:
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{3}{|c|}{Team sheet} \\
\hline
Goalkeeper & GK & Paul Robinson \\ \hline
Defenders & LB & Lucus Radebe \\
& DC & Michael Duberry \\
& DC & Dominic Matteo \\
& RB & Didier Domi \\ \hline
Midfielders & MC & David Batty \\
& MC & Eirik Bakke \\
& MC & Jody Morris \\ \hline
Forward & FW & Jamie McMaster \\ \hline
Strikers & ST & Alan Smith \\
& ST & Mark Viduka \\
\hline
\end{tabular}

Caption outside table?

I'm trying to add a caption to a table in latex, however it throws this error "! LaTeX Error: \caption outside float."
From the error I am guessing it means that it is outside the table, but I have clearly put it inside.
\begin{tabular}{|c|c|c|c|c|c|}
\caption{Table1}
Potentiometer & Resistance & \multicolumn{2}{c}{Calculated V\textsubscript{32}} & \multicolumn{2}{c|}{Measured V\textsubscript{32}}\\ \cline{3-6}
Position & R\textsubscript{34} & Amplitude & Phase & Amplitude & Phase\\ \hline \hline
1 & 303.8 & & 2.73 & 28.2 & 2.51\\
2 & 1.141k & & 1.81 & 28.2 & 1.63\\
3 & 3.453k & & 0.79 & 28.2 & 0.5\\
4 & 5.33k & & 0.53 & 28.2 & 0.38\\
5 & 7.45k & & 0.38 & 28.2 & 0.25\\
6 & 9.54k & & 0.30 & 28.2 & 0.13\\
7 & 10.84k & & 0.27 & 28.2 & 0.13\\
\hline
\end{tabular}
The tabular environment won't take a caption. You need to do something like this:
\begin{table}
\begin{tabular}{|c|c|c|c|c|c|}
Potentiometer & Resistance & \multicolumn{2}{c}{Calculated V\textsubscript{32}} & \multicolumn{2}{c|}{Measured V\textsubscript{32}}\\ \cline{3-6}
Position & R\textsubscript{34} & Amplitude & Phase & Amplitude & Phase\\ \hline \hline
1 & 303.8 & & 2.73 & 28.2 & 2.51\\
2 & 1.141k & & 1.81 & 28.2 & 1.63\\
3 & 3.453k & & 0.79 & 28.2 & 0.5\\
4 & 5.33k & & 0.53 & 28.2 & 0.38\\
5 & 7.45k & & 0.38 & 28.2 & 0.25\\
6 & 9.54k & & 0.30 & 28.2 & 0.13\\
7 & 10.84k & & 0.27 & 28.2 & 0.13\\
\hline
\end{tabular}
\caption{Table1}
\label{tab:xyz}
\end{table}
If you don't want to use a "float" (e.g. table or figure) that will "float away" from the place you define it, you can add:
\usepackage{capt-of}
in the preamble and then do something like:
\begin{center}
\captionof{table}{Caption text goes here}
\label{table1} % for use in \ref{table1} if you want to refer to the table number
\begin{tabular}{|c|c|c|c|c|c|}
% etc.
\end{tabular}
\end{center}
to add a auto-numbered caption to a non-float.

Resources