Skip to main content
Tables

Tables #

Cell #

Line breaks inside cell #

Refs:

The \hline’s are a hack without using any extra packages.

LaTeX table with line breaks in cells
\usepackage{makecell}

\begin{table}\centering
  \caption{Good table with line breaks}\label{tab:line-break}
  
  \begin{tabular}{lll}
    {} \\[-1.8ex]\hline
    \hline \\[-1.8ex]
    Head Col 1 & Head Col 2 & Head Col 3 \\ \hline \\[-1.8ex]
    Data Col 1 & Data Col 2 & \makecell[l]{here is \\ my text \\ centre-aligned} \\ \hline \\[-1.8ex]
    Data Col 1 & Data Col 2 & \makecell[tl]{here is \\ my text \\ top-aligned} \\ \hline \\[-1.8ex]
    Data Col 1 & Data Col 2 & \makecell[br]{here is \\ my text \\ bottom-aligned} \\
    \hline
    \hline \\[-1.8ex]
  \end{tabular}
\end{table}

Multi-column cell #

Replace any x cells with the code below, and continue as if you have put x cells.

\multicolumn{x}{l|r|c}{Cell contents…}

Multi-row cell #

Ref: tables - How to use \multirow correctly? - TeX - LaTeX Stack Exchange

LaTeX table with a multi-row cell
\usepackage{multirow}

\begin{table}\centering
  \caption{Good table with multiple row cells}\label{tab:multi-row}
  \begin{tabular}{lll}
    {} \\[-1.8ex]\hline
    \hline \\[-1.8ex]
    \multirow{4}{*}{Head Col 1} & Head Col 2 & Head Col 3 \\
                                & Data Col 2 & Data Col 3 \\
                                & Data Col 2 & Data Col 3 \\
                                & Data Col 2 & Data Col 3 \\
    \hline
    \hline \\[-1.8ex]
  \end{tabular}
\end{table}

Table #

Add end notes #

Stargaze does this automatically, but I was not happy that a particularly long note would widen the table. A comment in this question solved that problem for me.

If you have used \begin{tabular}{@{\extracolsep{5pt}}lcc}, write \multicolumn{3}{p{\textwidth}}{\hspace{-6pt}\textit{Notes:} ...} instead. The pixels for \hspace should be adjusted on a case-by-case basis.

This is because \multicolumn does not take the whole \linewidth, as explained here.

\begin{table}\centering
  \caption{Good table with multiple row cells}\label{tab:multi-row}
  \begin{tabular}{lll}
    {} \\[-1.8ex]\hline
    \hline \\[-1.8ex]
    \multirow{4}{*}{Head Col 1} & Head Col 2 & Head Col 3 \\
     & Data Col 2 & Data Col 3 \\
     & Data Col 2 & Data Col 3 \\
     & Data Col 2 & Data Col 3 \\
    \hline
    \hline \\[-1.8ex]
    \multicolumn{3}{p{\textwidth}}{\textit{Notes:} $^{\ast}p<0.1$; $^{\ast\ast}p<0.05$; $^{\ast\ast\ast}p<0.01$.}
  \end{tabular}
\end{table}

Make table sideways #

Ref: rotating - Vertical orientation landscape page in a PDF output file - TeX - LaTeX Stack Exchange

% choose one of the two packages:
\usepackage{lscape}     % if want the page upright
\usepackage{pdflscape}  % if want the page sideways

\begin{landscape}
\begin{table} \centering
\caption{Great table}\label{tab:great-table}
\begin{tabular}
...
\end{tabular}
\end{table}
\end{landscape}

Shrink tables that are too big #

Ref: scaling - Is there a way to slightly shrink a table, including font size, to fit within the column boundaries? - TeX - LaTeX Stack Exchange

My setup somehow does not like adjustbox or \resizebox. Will update if tested.

\usepackage{graphicx}

\begin{table} \centering
\caption{Great table}\label{tab:great-table}
\scalebox{0.85}{%
\begin{tabular}
...
\end{tabular}
}% end scalebox
\end{table}