texblog

Professional and clean tables with LaTeX

Tables are great to visualize data in a structured way. Unfortunately, too often I see tables which are cluttered and difficult to read and interpret. It takes little to make them more presentable and easier to read. This post advocates tidy and lean tables, to the benefit of the reader.

1. Add a caption which explains the data shown in the table

A table caption is added through the \caption macro, which automatically numbers the table. Usually, a table caption goes above a table. However, some editors require the caption to be placed below the table. Add the \caption macro before or after the tabular environment to place the caption above or below the table. To reference the table in the text, use \label. To get the correct reference number, the label has to be placed either right after the caption or into the caption macro.

\begin{table}[ht]
\centering
% To place a caption above a table
\caption{Caption above table.}
\begin{tabular}[t]{cc}
% Table content
\end{tabular}
% Or to place a caption below a table
\caption{Caption below table.}
\label{tab:caption}
\end{table}%

 

2. Omit vertical lines

Vertical lines can almost always be omitted. A professional table has three horizontal lines, two as table frame above and below and one to separate the header row from the data. The \hline macro inserts horizontal lines with the right length.

\begin{table}[ht]
\centering
\caption{A table without vertical lines.}
\begin{tabular}[t]{lcc}
\hline
&Treatment A&Treatment B\\
\hline
John Smith&1&2\\
Jane Doe&--&3\\
Mary Johnson&4&5\\
\hline
\end{tabular}
\end{table}%

 
The booktabs package provides commands to produce heavier lines as table frame (\toprule, \bottomrule) and lighter lines within a table (\midrule).

\usepackage{booktabs}

\begin{table}[ht]
\centering
\caption{Thicker horizontal lines above and below the table.}
\begin{tabular}[t]{lcc}
\toprule
&Treatment A&Treatment B\\
\midrule
John Smith&1&2\\
Jane Doe&--&3\\
Mary Johnson&4&5\\
\bottomrule
\end{tabular}
\end{table}%

 

3. Break lines within cells with fixed-width columns

To automatically break longer lines of text within cells, define fixed-width columns. The array package implements column types for fixed-width columns.

Column type Description
p{width} Top-aligned column
m{width} Middle-aligned column
b{width} Bottom-aligned column
>{\raggedright} Left-aligned column
>{\centering} Center-aligned column
>{\raggedleft} Right-aligned column

Vertical and horizontal alignment can be combined. The example below creates a fixed-width column of 10% of the total line-width. Furthermore, text in this column is top-aligned and centered. I recommend to use this notation over a fixed length (e.g. 2cm). It helps keep the total table width within the page width available. Importantly, in the last column, the \\ command has to be restored using \arraybackslash.

\usepackage{array}

% Any column
>{\centering}p{0.1\linewidth}

% Last column
>{\centering\arraybackslash}p{0.1\linewidth}

 
Here is the table from before with fixed-width columns and text instead of numbers for illustration.

\usepackage{array}

\begin{table}[ht]
\centering
\caption{Fixed-width columns.}
\begin{tabular}[t]{l>{\raggedright}p{0.3\linewidth}>{\raggedright\arraybackslash}p{0.3\linewidth}}
\toprule
&Treatment A&Treatment B\\
\midrule
John Smith&Good response, no side-effects&No response\\
Jane Doe&--&Good response, no side-effects\\
Mary Johnson&No response&Good response with side-effects\\
\bottomrule
\end{tabular}
\end{table}%

With fixed-width columns, the column-type definition tends to be rather lengthy. If multiple columns of the same type are defined, use the star notation. See here for an article on the topic.

% n: number columns; type: column-type definition
*{n}{type}

% For example the column type definition above can be shortened to:
\begin{tabular}{l*{2}{>{\raggedright\arraybackslash}p{0.3\linewidth}}}

 

4. Add extra space between rows

To clearly separate rows, add extra white-space. The simplest way is through \arraystretch, which “stretches” the table vertically. To increase white-space between rows, use a factor greater than 1.

\renewcommand\arraystretch{1.5}

 

5. Don’t repeat text, use multi-row and multi-column macros instead

I wrote about how to create multi-row and multi-column cells in a table here. Multi-row cells require the multirow package.

 

6. Large tables

Ideally, a table fits on a single page. If that’s not possible for some reason, here are a few suggestions that might help. Several suggestions may be combined.

Landscape full-page table
If the table fits better on a landscape format page, insert a page in landscape format. The p option centers the table vertically on the page.

\usepackage{lscape}

\clearpage
\begin{landscape}
\begin{table}[p]
\centering
\caption{Landscape format table.}
\begin{tabular}[t]{lcc}
\toprule
&Treatment A&Treatment B\\
\midrule
John Smith&1&2\\
Jane Doe&--&3\\
Mary Johnson&4&5\\
\bottomrule
\end{tabular}
\end{table}%
\end{landscape}
\clearpage

 
Use the longtable package
The longtable package automatically breaks long tables across multiple pages. It requires extra configuration. See my article on that topic for an example and consult the package documentation.

 
Reduce white-space
There are different ways to reduce white-space in a table. To reduce horizontal space, define \arraystretch to be a factor less than 1.

\renewcommand\arraystretch{0.8}

To reduce vertical space, reduce the space between columns through \tabcolsep.

\renewcommand{\tabcolsep}{3pt}

 
Decrease the font size
Although I wouldn’t generally recommend it, using a smaller font size might help to fit a large table on a single page. I wrote about changing the font size in LaTeX here.

\begin{table}[ht]
\centering
\caption{Table with ``small'' font size.}
\begin{small}
\begin{tabular}[t]{cll}
% Table content
\end{tabular}
\end{small}
\end{table}%

 

7. Get in touch

If you need professional help with tables in LaTeX, get in touch.

Exit mobile version