Blog

Publication-quality tables in LaTeX: booktabs and siunitx, from spreadsheet to paper

Most LaTeX tables in first drafts look the same: a vertical line between every column, a horizontal line under every row, and numbers that wander left and right because 0.012 and 0.084 were typed as text. Journals redo these tables, or send them back. The fix isn't hard. Two packages, booktabs and siunitx, and a few habits produce tables that look like the ones in the papers you read.

This guide builds three tables from a typical lab notebook: a simple one, one with decimal-aligned values and uncertainties, and one with grouped columns and a footnote. All the code compiles as is with a standard TeX distribution.

The three rules of a good table

  1. No vertical lines. Column alignment and white space separate columns better than rules do.
  2. Three horizontal rules at most: one at the top, one under the header, one at the bottom (\toprule, \midrule, \bottomrule from booktabs). They have different thicknesses and correct spacing around them, which \hline does not.
  3. Numbers align on the decimal point, units go in the header and not in every cell, and a value's uncertainty is written once, in a consistent form.

Example 1: a plain booktabs table

Result

The compiled table, with three horizontal rules and no vertical lines. Caption above it: Table 1: Melting points of the three samples. Columns: Sample, Batch, Melting point (°C). Rows: A, 1, 121.4; B, 1, 118.9; C, 2, 123.0.

LaTeX source

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htbp]
  \centering
  \caption{Melting points of the three samples.}
  \label{tab:melting}
  \begin{tabular}{lcc}
    \toprule
    Sample & Batch & Melting point (\unit{\celsius}) \\
    \midrule
    A & 1 & 121.4 \\
    B & 1 & 118.9 \\
    C & 2 & 123.0 \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

Open in Lilia

This example is a complete document. Open it in Lilia to change it and compile it yourself, or download the PDF it produces: no account is needed for that.

A few details are worth copying:

  • The caption goes above the table. That's the convention in most journals (figures get it below). Put \label after \caption, or the reference points at the wrong counter.
  • The unit sits in the header, typeset by \unit{\celsius} so the degree sign and spacing are right.
  • [htbp] lets LaTeX float the table to a sensible place instead of forcing it where you typed it.

Example 2: decimal alignment and uncertainties with siunitx

The S column type from siunitx aligns numbers on the decimal point and understands uncertainties in parentheses, 0.031(2), meaning 0.031 ± 0.002. table-format tells it how much room to reserve: 1.3(1) means one digit before the point, three after, and a one-digit uncertainty.

Result

The compiled table. Caption: Table 1: Rate constants at three temperatures (mean ± s.d., n = 3). Columns: T (K), k (s⁻¹), t½ (s), with the numbers aligned on the decimal point. Rows: 298, 0.012(1), 57.8; 310, 0.031(2), 22.4; 323, 0.084(5), 8.3.

LaTeX source

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htbp]
  \centering
  \caption{Rate constants at three temperatures (mean $\pm$ s.d., $n = 3$).}
  \label{tab:rates}
  \begin{tabular}{
      S[table-format=3.0]
      S[table-format=1.3(1)]
      S[table-format=2.1]
    }
    \toprule
    {$T$ (\unit{\kelvin})} & {$k$ (\unit{\per\second})} & {$t_{1/2}$ (\unit{\second})} \\
    \midrule
    298 & 0.012(1) & 57.8 \\
    310 & 0.031(2) & 22.4 \\
    323 & 0.084(5) &  8.3 \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

Open in Lilia

This example is a complete document. Open it in Lilia to change it and compile it yourself, or download the PDF it produces: no account is needed for that.

Two things trip people up here:

  • Header cells in an S column must be wrapped in braces ({$T$ (\unit{\kelvin})}). Otherwise siunitx tries to read the text as a number and stops with an error.
  • Use \unit for units on their own and \qty for a number with a unit in running text: \qty{12}{\kelvin}. In older documents you'll see \si and \SI. They still work in siunitx version 3, but \unit and \qty are the current names.

If you'd rather show the uncertainty as ± in the PDF, add \sisetup{uncertainty-mode = separate} to the preamble. The source stays the same.

Example 3: grouped headers and table notes

Results tables often compare methods on several datasets. \multicolumn spans a header across columns, and \cmidrule(lr){2-3} draws a short rule under it, trimmed at both ends so neighbouring groups don't touch. For a footnote that belongs to the table rather than the page, threeparttable keeps the note under the table, at the table's width.

Result

The compiled table. Caption: Table 1: Accuracy of two classifiers on two datasets. The headers Dataset 1 and Dataset 2 each span two columns, Acc. (%) and F1 (%), with a short rule under each group. Rows: Baseline, 71.2, 68.4, 64.0, 60.3; Ours (note a), 86.5, 84.1, 79.8, 77.2. Note a, under the table: Mean of five runs with different random seeds.

LaTeX source

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{threeparttable}

\begin{document}
\begin{table}[htbp]
  \centering
  \caption{Accuracy of two classifiers on two datasets.}
  \label{tab:grouped}
  \begin{threeparttable}
  \begin{tabular}{l S[table-format=2.1] S[table-format=2.1]
                    S[table-format=2.1] S[table-format=2.1]}
    \toprule
    & \multicolumn{2}{c}{Dataset 1} & \multicolumn{2}{c}{Dataset 2} \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5}
    Method & {Acc. (\%)} & {F1 (\%)} & {Acc. (\%)} & {F1 (\%)} \\
    \midrule
    Baseline      & 71.2 & 68.4 & 64.0 & 60.3 \\
    Ours\tnote{a} & 86.5 & 84.1 & 79.8 & 77.2 \\
    \bottomrule
  \end{tabular}
  \begin{tablenotes}\footnotesize
    \item[a] Mean of five runs with different random seeds.
  \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

Open in Lilia

This example is a complete document. Open it in Lilia to change it and compile it yourself, or download the PDF it produces: no account is needed for that.

Refer to any of these from the text with Table~\ref{tab:rates}. The ~ is a non-breaking space, so "Table" and its number never end up on different lines.

Common problems and quick fixes

Symptom Likely cause Fix
Invalid number error from siunitx Text in an S column, or a header not in braces Wrap the cell in {…}
Table wider than the column Too many columns or long headers \small before \begin{tabular}, shorter headers with units in the caption, or a two-column-wide float (table*)
Rules look cramped or too thick \hline mixed with booktabs Use only \toprule/\midrule/\bottomrule/\cmidrule
"Table ??" in the PDF \label before \caption, or a typo in the key Move \label after \caption; compile twice
Numbers misaligned Column declared c instead of S Use S[table-format=…]

Doing it in Lilia

Lilia is a browser editor where a paper is a sequence of blocks with LaTeX underneath. Here's how the same tables come together there. (The steps follow Lilia's own help pages, starting with Data → LaTeX table.)

From a spreadsheet. Copy the cells from Excel, LibreOffice or Google Sheets (tab-separated) or a CSV, and paste them into the LaTeX table tool, or into the table block in the editor. The first row becomes the header. Set a caption and a label such as tab:rates, then Open in the editor. Lilia writes a booktabs table: no vertical rules, with \toprule, \midrule and \bottomrule. You can then refine the LaTeX by hand.

From existing LaTeX. If you already have the table code, use Paste LaTeX from the command palette (the ? button in the top bar), or import your whole .tex file or Overleaf zip from Import / Export. The import shows a review of what came across before anything is created.

Check that it compiles. Click the shield in the left rail (Validate), then Validate now. Lilia compiles the document with a real TeX engine. If a header cell in an S column is missing its braces, the error appears against the table block it comes from, not as a line number in a log.

Refer to it. Type @ in a paragraph and pick the labelled table. Lilia inserts the cross-reference and renumbers it if you move things around.

Hand it on. Export → LaTeX gives a single .tex or a project .zip (flat or Overleaf-style), and PDF and Word (.docx) are in the same dialog. The table goes with you as ordinary LaTeX.

Summary

  • Use booktabs rules: top, mid, bottom, and \cmidrule for groups. No vertical lines.
  • Put numbers in siunitx S columns with a table-format, and units in the header with \unit.
  • Put the caption above the table and the \label after the caption.
  • Use threeparttable for notes that belong to the table.

If you'd like to try this without installing anything, Lilia's Free plan includes 3 documents, every export format and the compile check: liliaeditor.com.