Latex (texmaker) table \cline - latex

I'm having this problem with creating table in Latex.
So I want to create a table but when I use \cline it gives me
error ! Paragraph ended before \#cline was complete.\par
and much more.
I'm using \usepackage{multiraw}, \usepackage{tabulary} for tables.
The table:
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{laktóza $ [\mathrm{mmol \cdot dm^{-3}}] $} & \multirow{2}{*}{} & \multicolumn{5}{c|}{ONPG $ [\mathrm{mmol \cdot dm^{-3}}] $} \\ \
& & \multicolumn{1}{c|}{0,10} & \multicolumn{1}{c|}{0,25} & \multicolumn{1}{c|}{0,50} & \multicolumn{1}{c|}{1,0} & \multicolumn{1}{c|}{2,0} \\ \
\hline
\multirow{2}{*}{0} & $ V_{ONPG} \enskip [\mathrm{\mu l}] $ & 10 & 25 & 50 & 100 & 200 \\ \cline{2-7}
& $ V_{roztok \enskip Z} \enskip [\mathrm{\mu l}] $ & 990 & 975 & 950 & 900 & 800 \\ \ \hline
\end{tabular}
\end{table}
Thanks for every help.

\documentclass{article}
\usepackage{multirow}
\usepackage{tabulary}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{laktóza $ [\mathrm{mmol \cdot dm^{-3}}] $} & \multirow{2}{*}{} & \multicolumn{5}{c|}{ONPG $ [\mathrm{mmol \cdot dm^{-3}}] $} \\
& & \multicolumn{1}{c|}{0,10} & \multicolumn{1}{c|}{0,25} & \multicolumn{1}{c|}{0,50} & \multicolumn{1}{c|}{1,0} & \multicolumn{1}{c|}{2,0} \\
\hline
\multirow{2}{*}{0} & $ V_{ONPG} \enskip [\mathrm{\mu l}] $ & 10 & 25 & 50 & 100 & 200 \\
\cline{2-7}
& $ V_{roztok \enskip Z} \enskip [\mathrm{\mu l}] $ & 990 & 975 & 950 & 900 & 800 \\
\hline
\end{tabular}
\end{table}
\end{document}
This code compiles and the output should now look like in your thoughts:
Some \ after \\ and before \hline were not supposed to be and produced errors (compare lines 5, 6 and 9 of your code with mine).

Related

How to fit a Latex table to a given document size?

I tried a lot of things to fit the table to the given size of the document. Unfortunately it did not work without destroying the format.
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{table}[!htbp] \centering
\begin{tabular} {#{\extracolsep{1pt}}lcc}
\\[-1.8ex]\hline
& \multicolumn{2}{c}{\textit{First Stage Regression}} \
\cr \cline{2-3}
\hline \\[-1.8ex]
\\[-1.8ex] & \multicolumn{1}{c}{ \% foreign born
while in college} & \multicolumn{1}{c}{\% foreign born
while in high
school} \\
\\[-1.8ex] & (1) & (2) \\
\hline \\[-1.8ex]
1960 Distribution
of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07 $^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline \\[-1.8ex]
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
\end{document}
Does anyone have an idea? Thanks
I suggest to use a table* environment so that your table will span over both columns.
You can safe some room by making very long cells into multi-line cells. The tabularray package makes this easy.
Are you 100% sure that your document is really encoded in latin1? That sounds very usual this millennium...
You should load the hyperref package after the other packages.
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{tabularray}
\usepackage{hyperref}
\begin{document}
\begin{table*}
\begin{tblr}{
colspec={X[l]X[c]X[c]},
}
\hline
& \SetCell[c=2]{} \textit{First Stage Regression} & \\
\cline{2-3}
& \% foreign born while in college (1) & \% foreign born while in high school (2)\\
\hline
\SetCell[r=2]{} 1960 Distribution of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07$^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline
\textit{Note:} & \SetCell[c=2]{r} $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01 \\
\end{tblr}
\end{table*}
\end{document}
Just add the \resizebox parameter before tabular and don't forget to add the brackets before and after the tabular. You can put it in different ways, such as \resizebox{\textwidth}{!}, \resizebox{0.5\textwidth}{!}, \resizebox{3cm}{!}, ...
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{table}[!htbp] \centering
\resizebox{\textwidth}{!}{
\begin{tabular} {#{\extracolsep{1pt}}lcc}
\\[-1.8ex]\hline
& \multicolumn{2}{c}{\textit{First Stage Regression}} \
\cr \cline{2-3}
\hline \\[-1.8ex]
\\[-1.8ex] & \multicolumn{1}{c}{ \% foreign born
while in college} & \multicolumn{1}{c}{\% foreign born
while in high
school} \\
\\[-1.8ex] & (1) & (2) \\
\hline \\[-1.8ex]
1960 Distribution
of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07 $^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline \\[-1.8ex]
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
}
\end{table}
\end{document}

Overfull \hbox and Package array Errors. Latex tabular

I am getting trouble to fit my table - tabular to the paragraph width.
This is the error:
Overfull \hbox (341.06795pt too wide) in paragraph at lines 391--411
Package array Error: Illegal pream-token (M): `c' used.
Package array Error: Illegal pream-token (4cm): `c' used
I have been trying one thousand things and nothing seems to work.
I am using this template from Overleaf, where you can find the document class.
This is my code.
\documentclass{JASSS}
\usepackage{amsmath,systeme}
\usepackage{tabularx,colortbl}
\usepackage{booktabs}
\title{XXXXX}
\reviewcopy{true}
\author[1]{}
\affil[1]{}
\email{XX}
\usepackage{natbib}
\setcitestyle{authoryear,round,aysep={}}
\begin{document}
\maketitle
\begin{abstract}
Bla bla
\end{abstract}
\section{xxxx}
\begin{table}[h!]
\centering
\begin{tabular}{ |M{4cm}||M{4cm}|M{4cm}|M{4cm}|}
% \begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{Initial value parameter combinations ($t_0=1932$)} \\
\hline
Scenarios from 2020 & $\phi_{B}=\phi_{C}=0.05$ and 1932 electoral results & $\phi_{B}=0.05, \phi_{C}=0.055$ and 1932 electoral results & $\phi_{B}=\phi_{C}=0.05$ and electoral tie \\
\hline
$\phi_{D}=\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0000 & S0100 & S1000 \\
\hline
\rowcolor{blue!20}
$\phi_{D}=0.015,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0001 & S0101 & S1001 \\
\hline
\rowcolor{red!20}
$\phi_{D}=0.01,\phi_{E}=0.015$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0010 & S0110 & S1010 \\
\hline
\rowcolor{yellow!20}
$\phi_{D}=0.01,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.015$ & S0011 & S0111 & S1011 \\
\hline
\end{tabular}
\bibliographystyle{jasss}
\bibliography{references}
\end{document}
The M column type is not defined by default. If you want to use it, you have to somehow define it. I don't know what you indent it to do, but here some dummy code:
\documentclass{JASSS}
\usepackage{array}
\usepackage{amsmath,systeme}
\usepackage{tabularx,colortbl}
\usepackage{booktabs}
\newcolumntype{M}[1]{p{#1}}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{ |M{4cm}||M{4cm}|M{4cm}|M{4cm}|}
% \begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{Initial value parameter combinations ($t_0=1932$)} \\
\hline
Scenarios from 2020 & $\phi_{B}=\phi_{C}=0.05$ and 1932 electoral results & $\phi_{B}=0.05, \phi_{C}=0.055$ and 1932 electoral results & $\phi_{B}=\phi_{C}=0.05$ and electoral tie \\
\hline
$\phi_{D}=\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0000 & S0100 & S1000 \\
\hline
\rowcolor{blue!20}
$\phi_{D}=0.015,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0001 & S0101 & S1001 \\
\hline
\rowcolor{red!20}
$\phi_{D}=0.01,\phi_{E}=0.015$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0010 & S0110 & S1010 \\
\hline
\rowcolor{yellow!20}
$\phi_{D}=0.01,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.015$ & S0011 & S0111 & S1011 \\
\hline
\end{tabular}
\end{table}
\end{document}

How can somene create two tables side by side in beamer?

How can somene create two tables side by side in beamer? I use the following to insert one table
\begin{table}
\begin{tabular}{l | c | c | c | c | c}
Model & intercept & X & Y & Adjusted $R^2$ & \\
\hline \hline
Coeff & 2.229 & -0.274 & 1.221 & 38\%\\
t-value & 3.404 & -0.49 & 3.907 \\
GMM-t & 2.542 & -0.444 & 3.814\\
\end{tabular}
\end{table}
which command should I use to have two tables side by side like the aforementioned table?
If your tables are narrow enough to fit side by side, you can simply place them next to each other like you would do for any normal letter.
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{table}
\begin{tabular}{l | c | c | }
Model & intercept & X \\
\hline \hline
Coeff & 2.229 & -0.274 \\
t-value & 3.404 & -0.49\\
GMM-t & 2.542 & -0.444 \\
\end{tabular}
\hfill
\begin{tabular}{l | c | c | }
Model & intercept & X \\
\hline \hline
Coeff & 2.229 & -0.274 \\
t-value & 3.404 & -0.49\\
GMM-t & 2.542 & -0.444 \\
\end{tabular}
\end{table}
\end{frame}
\end{document}
As suggested by this blog, you can try columns environment. For example, with code like
\begin{frame}{Example}
\begin{columns}
\begin{column}{0.3\textwidth}
\begin{table}
\begin{tabular}{c|c|c}
sid & bid & day \\ \hline \hline
22 & 101 & 10/10/96 \\
58 & 103 & 11/12/96 \\
\end{tabular}
\caption{reserves}
\end{table}
\end{column}
\begin{column}{0.3\textwidth}
\begin{table}
\begin{tabular}{c|c|c|c}
sid & sname & rating & age \\ \hline \hline
22 & dustin & 7 & 45.0 \\
31 & lubber & 8 & 55.5 \\
58 & rusty & 10 & 35.0 \\
\end{tabular}
\caption{Sailors}
\end{table}
\end{column}
\end{columns}
\end{frame}
You can get something like below (ignoring the background image)

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: how does the include-command work?

I supposed the include-command copy-pastes code in the compilation, it is wrong because the code stopped working. Please, see the middle part in the code. I only copy-pasted the code to the file and added the include-command.
$ cat results/frames.tex
10.31 & 8.50 & 7.40 \\
10.34 & 8.53 & 7.81 \\
8.22 & 8.62 & 7.78 \\
10.16 & 8.53 & 7.44 \\
10.41 & 8.38 & 7.63 \\
10.38 & 8.57 & 8.03 \\
10.13 & 8.66 & 7.41 \\
8.50 & 8.60 & 7.15 \\
10.41 & 8.63 & 7.21 \\
8.53 & 8.53 & 7.12 \\
Latex code, see the middle part
\begin{table}
\begin{tabular}{ | l | m | r |}
\hline
$t$ / s & $d_{1}$ / s & $d_{2}$ / s \\
$\Delta h = 0,01 s$ & $\Delta d = 0,01 s$ & $\Delta d = 0,01 s$ \\
\hline
% I JUST COPIED THE CODE from here to the file, included.
% It stopped working, why?
\include{results/frames.tex}
\hline
$\pi (\frac{d_{1}}{2} - \frac{d_{2}}{2})$ & $2 \pi R h$ & $2 \pi r h$ \\
\hline
\end{tabular}
\end{table}
Use \input instead of \include, that will work.
\include additionally performs a \clearpage command which will not work in the context of a table.
Try with \input, \include is old and very limited..

Resources