LaTeX Tables

Overview

Useful reference: Wiki Link.

Hint

The commands: \toprule, \midrule, and \bottomrule are all convenience shortcuts for pre-defined table rule commands (from the booktabs package). They define a certain default thickness and spacing. Users can use these interchangeably or not at all depending on the type of rule they want. If the spacing is to their liking, users can optionally pass in a thickness argument to override the default thickness of each rule.

\toprule[1pt]
\midrule[3pt]
\bottomrule[5pt]

Further, users can specify their own custom rule using the \specialrule command (also from the booktabs package) for the most amount of control and customization, for example:

\specialrule{<thickness>}{<abovespace>}{<belowspace>}

\specialrule{10pt}{0pt}{0pt}

Table with Caption

\begin{table}[H]
   \caption{Example LaTeX Table} 
   \label{tab:example}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}
../_images/table_caption.png

Table with Inside Border

\begin{table}[H]
   \caption{Example LaTeX Table} 
   \label{tab:example}
   \small
   \centering
   \begin{tabular}{l|c|c|r}
   \toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}
../_images/table_inisde_border.png

Table with Full Border

\begin{table}[H]
   \caption{Example LaTeX Table} 
   \label{tab:example}
   \small
   \centering
   \begin{tabular}{|l|c|c|r|}
   \midrule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4\\
   \midrule
   \end{tabular}
\end{table}
../_images/table_outside_border.png

Table with Row Span

\begin{table}[H]
   \caption{Example LaTeX Table with \texttt{\textbackslash multicolumn}} 
   \label{tab:example_multicolumn}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   \multicolumn{3}{c}{Multiple Column Entry} & Item 4 \\
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}
../_images/table_multicol.png

Table with Column Span

\begin{table}[H]
   \caption{Example LaTeX Table with \texttt{\textbackslash multirow}}  
   \label{tab:example_multirow}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   \multirow{2}{*}{Multiple Row Entry} & Item 2 & Item 3 & Item 4 \\
                                       & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}
../_images/table_multirow.png

Referencing Tables

The example below highlights how the \label command is used to define a unique label to this specific table and how it can be referenced within the text of the document using the \ref command.

\begin{table}[H]
   \caption{Example LaTeX Table} 
   \label{tab:example}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}

An example table can be seen in \ref{tab:example}.
Also note how the "Table" prefix is automatically added within the document text whenever the reference is called.
../_images/reference_table.png

Referencing Range of Tables

The example below highlights how the \refrange command can be used to reference a range of tables.

\begin{table}[H]
   \caption{Table A} 
   \label{tab:tab-a}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}

\begin{table}[H]
   \caption{Table B} 
   \label{tab:tab-b}
   \small
   \centering
   \begin{tabular}{lccr}
   \toprule\toprule
   \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} & \textbf{Header 4} \\ 
   \midrule
   Item 1 & Item 2 & Item 3 & Item 4 \\
   Item 1 & Item 2 & Item 3 & Item 4\\
   \bottomrule
   \end{tabular}
\end{table}

We can reference a range of tables as seen here: \refrange{tab:tab-a}{tab:tab-b}.
Also note how the "Tables" prefix is automatically added within the document text whenever the range reference is called.
../_images/reference_range_tables.png