Having problems fitting a table to a Column in LaTeX - 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}

Related

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}

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:

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 - 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}

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.

Resources