Overfull \hbox and Package array Errors. Latex tabular - latex

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}

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}

Having problems fitting a table to a Column in LaTeX

I have my template set that subsections go into 2 columns, however when I try and insert a table, it does not compile instead being left blank. I think the reason is that the table is too wide/not being fitted.
Here is my LaTeX
\subsection{On examination}
\begin{table}[]
\begin{tabular}{|l|l|l|}
\hline
{\ul \textbf{Symptom}} & {\ul \textbf{Patient}} & {\ul \textbf{Normal}} \\ \hline
\textit{Temperature} & 36.7C & 36-36.8 \\ \hline
\textit{BMI} & 31 kg/m\textasciicircum{}2 & 18.5-24.9 \\ \hline
\textit{Heart Rate} & 70bpm & 60-100bpm \\ \hline
\textit{Blood Pressure} & 145/80 mmHg & \textless{}140/90mmHg \\ \hline
\textit{Respiratory Rate} & 12 breaths/min & 12-18 breaths/min \\ \hline
\textit{Misc} & & \\ \hline
\end{tabular}
\end{table}

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)

How to fix an extra alignment and illegal character error when making a table in LaTex, Overleaf

I have created a table in Latex and it has stopped displaying it but I need it to work on the document I am currently working on. When I input into a new document, it works again. I am getting the following errors:
LaTex error: Illegal character in array arg. Overfull \Hbox (56.47151pt too wide) in paragraph at lines at lines 70--98
Error alignment tab has been changed to \cr.
It does not work either when I include the array package. I am using the following packages:
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{url}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{float}
\usepackage{amsmath}
\usepackage[toc,page]{appendix}
\begin{table}[h!]
\begin{center}
\caption{A comparison between Rwanda and The Gambia}
\begin{tabular}{l|s|r|m}
\textbf{Variable} &
\textbf{Specific Variable} &
\textbf{Rwanda} &
\textbf{Gambia} &
\hline \hline
\textit{Size} & Surface area (sq. km) & 26,340 & 11,300 \\
& Population (total) & 12,208,407 & 2,100,568 \\
\hline
\textit{Economy} & GDP growth (annual \%) & 6.1 & 4.6 \\
& GDP per capita & 720 & 680 \\
\hline
\textit{Education} & Literacy rate (gender parity index) & 1.029 & 0.851 \\
& School enrolment (primary \% gross) & 133.425 & 97.115 \\
& School enrolment (secondary \% gross) & 32.988 & 57.096 \\
& School enrolment (tertiary \% gross) & 6.695 & 3.094 \\
\hline
\textit{Health and Survival} & Life expectancy at birth (total years) & 67.129 & 61.193 \\
\hline
\textit{Politics} & Political Elections & 4 & 8 \\
& Freedom Rights Score & Not Free & Not Free \\
\hline
\textit{Gender Equality} & Gender equality rating & 4.5 & 3.5 \\
& The Global Gender Gap Report& 121 & 6 \\
\hline
\textit{Aid Rates} & Net ODA received per capita & 100.373 & 128.356 \\
& Net official development assistance & 37.3 & 46.8 \\
\end{tabular}
\end{center}
\end{table}
Concerning the first problem, "Illegal character in array arg", it is indeed cause by by an unrecognised argument to tabular.
Legal arguments are supposed to describe column types and are c (centered), l (left aligned), r (right aligned), p{width} (top aligned paragraph) and | to describe an intercolumn rule for the most common ones. There are packages that add extra column types, but in your code \begin{tabular}{l|s|r|m} 's' is unknown and do not correspond to a valid column type. 'm' exists to specify a middle aligned paragraph in the 'array' package; it would require the insertion of the package and an extra argument with the desired width of the paragraph. Just change 's' and 'm' wih legal parameters and all is OK. There are many documentation available that describe valid column types.
The second message says that you specify an array with four columns but the fist line contains 5 entries:
\textbf{Variable} &
\textbf{Specific Variable} &
\textbf{Rwanda} &
\textbf{Gambia} &
the fifth one is an empty entry following the ampersand after 'Gambia'. Replace it with an end-of-line to suppress the problem.
Here is a corrected version.
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{url}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{float}
\usepackage{amsmath}
\usepackage[toc,page]{appendix}
\begin{document}
\begin{table}[h!]
\begin{center}
\caption{A comparison between Rwanda and The Gambia}
\begin{tabular}{l|c|r|c}
\textbf{Variable} &
\textbf{Specific Variable} &
\textbf{Rwanda} &
\textbf{Gambia} \\
\hline \hline
\textit{Size} & Surface area (sq. km) & 26,340 & 11,300 \\
& Population (total) & 12,208,407 & 2,100,568 \\
\hline
\textit{Economy} & GDP growth (annual \%) & 6.1 & 4.6 \\
& GDP per capita & 720 & 680 \\
\hline
\textit{Education} & Literacy rate (gender parity index) & 1.029 & 0.851 \\
& School enrolment (primary \% gross) & 133.425 & 97.115 \\
& School enrolment (secondary \% gross) & 32.988 & 57.096 \\
& School enrolment (tertiary \% gross) & 6.695 & 3.094 \\
\hline
\textit{Health and Survival} & Life expectancy at birth (total years) & 67.129 & 61.193 \\
\hline
\textit{Politics} & Political Elections & 4 & 8 \\
& Freedom Rights Score & Not Free & Not Free \\
\hline
\textit{Gender Equality} & Gender equality rating & 4.5 & 3.5 \\
& The Global Gender Gap Report& 121 & 6 \\
\hline
\textit{Aid Rates} & Net ODA received per capita & 100.373 & 128.356 \\
& Net official development assistance & 37.3 & 46.8 \\
\end{tabular}
\end{center}
\end{table}
\end{document}

Latex - Issue on newcommand and Tabular

The following code is producing error: Incomplete \if; all text was ignored after line.
I tried adding \\ on the end each if (...\eval{#1+#2}}}} \\%). But this only added a line on my table.
\begin{table}[H]
\tiny
\centering
\def\arraystretch{2}
\setlength{\tabcolsep}{5.2pt}
\caption{xxxxx}
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\eval}{m}{\int_eval:n {#1}}
\ExplSyntaxOff
\newcommand*{\drawtable}[5]{%
\if a#5%
\multicolumn{1}{c}{\multirow{1}{*}{#1}} & \multicolumn{1}{c}{\multirow{1}{*}{#2}} & \multicolumn{1}{c}{\multirow{1}{*}{\textbf{\eval{#1+#2}}}}%
\else\if b#5%
\multicolumn{1}{c}{\multirow{1}{*}{#3}} & \multicolumn{1}{c}{\multirow{1}{*}{#4}} & \multicolumn{1}{c}{\multirow{1}{*}{\textbf{\eval{#3+#4}}}}%
\fi\fi%
}%
\begin{tabular}{ccccccccccccccccccccccccc}
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{3}{c}{\multirow{1}{*}{\textbf{xxxxx}}} & \\ \hline
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{2}{c}{\multirow{1}{*}{\textbf{yyy}}} & \\ \cline{3-4}
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{aa}}} &
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{bb}}} &
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{ccc}}} & \\ \hline
\multicolumn{1}{c}{\multirow{2}{*}{\textbf{rr}}} &
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{N.}}} &
\drawtable{18}{8}{4}{7}{a}
& \\
\multicolumn{1}{c}{\multirow{1}{*}{}} &
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{N.}}} &
\drawtable{18}{8}{4}{7}{b}
& \\ \hline
\end{tabular}
\end{table}

Resources