Tables are the backbone of technical documents—conveying numerical data, comparing metrics, and summarizing results. Yet standard LaTeX tabular environments often produce cramped spacing, inconsistent rules, and manual unit formatting headaches. By combining the booktabs
package for elegant horizontal rules and siunitx
for automatic number and unit alignment, you can create publication-quality tables that are both visually appealing and semantically robust. In this post, we’ll walk through eight practical patterns—from minimal setup and column types to complex multi‐row layouts and custom units—complete with ready-to-copy code snippets.
This guide assumes you know basic LaTeX. We’ll cover:
S
columns for numeric alignment\si{…}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
detect-mode,
tight-spacing = true,
table-format = 3.2,
output-decimal-marker = {.},
}
Explanation: Load booktabs
before defining your tabular. Configure siunitx
for number alignment, decimal marker style, and to inherit document fonts.
S
Columns
\begin{table}[ht]
\centering
\begin{tabular}{l S[table-format=2.1] S[table-format=3.0]}
\toprule
{Experiment} & {Value (\,\si{\metre})} & {Count} \\
\midrule
A & 1.2 & 12 \\
B & 10.0 & 100 \\
C & 0.34 & 5 \\
\bottomrule
\end{tabular}
\caption{Aligned numbers in S-columns.}
\end{table}
Explanation: The column specifier S
tells siunitx
to parse and align numbers on their decimal points. You can override table-format
per-column for different precisions.
\begin{tabular}{l S[table-format=3.1] S}
\toprule
{Material} & {Length (\si{\centi\metre})} & {Density (\si{\gram\per\cubic\centi\metre})} \\
\midrule
Steel & 12.3 & 7.85 \\
Aluminum & 25.0 & 2.70 \\
Brass & 18.6 & 8.50 \\
\bottomrule
\end{tabular}
Explanation: Wrap units in \si{…}
for consistent spacing and font. siunitx
handles prefixes, fractions, and spacing per the SI standard.
\sisetup{
output-decimal-marker = {,},
group-separator = {.},
group-minimum-digits = 4,
}
\begin{tabular}{S[table-format=5.3]}
\toprule
{Measurement} \\
\midrule
1234.567 \\
98765.432 \\
12.000 \\
\bottomrule
\end{tabular}
Explanation: European-style decimals and thousand separators are trivial to set globally or per-table.
\usepackage{multirow}
\begin{tabular}{l S[table-format=2.1] S[table-format=2.1]}
\toprule
\multirow{2}{*}{Category} & \multicolumn{2}{c}{Results} \\
& {A (\si{\metre})} & {B (\si{\metre})} \\
\midrule
X & 1.2 & 0.8 \\
Y & 2.3 & 1.5 \\
\bottomrule
\end{tabular}
Explanation: Combine multirow
and \multicolumn
with booktabs
rules for clean, semantically grouped headers.
\setlength{\tabcolsep}{4pt} % reduces default padding
\begin{tabular}{l S S}
\toprule
Test & {Value} & {Error} \\
\midrule
α & 5.1 & 0.2 \\
β & 3.4 & 0.1 \\
\bottomrule
\end{tabular}
Explanation: The length \tabcolsep
controls half-spacing around each column. Tweak globally or locally inside a group.
\usepackage[table]{xcolor}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{l S S}
\toprule
Item & {Mean} & {Std Dev} \\
\midrule
P & 1.23 & 0.05 \\
Q & 2.34 & 0.07 \\
R & 0.98 & 0.02 \\
\bottomrule
\end{tabular}
Explanation: Use xcolor
with the table
option and \rowcolors
to improve readability in dense tables.
\newcommand{\TableCaptionLabel}[2]{%
\caption{#1}\label{tab:#2}%
}
\begin{table}[ht]
\centering
\begin{tabular}{l S}
\toprule
Metric & {Value} \\
\midrule
Accuracy & 98.7 \\
Precision & 97.5 \\
\bottomrule
\end{tabular}
\TableCaptionLabel{Classification results on test set}{classification-results}
\end{table}
Explanation: A custom macro standardizes caption formatting and label prefixes, streamlining cross-referencing.