Professional-looking tables in LaTeX with booktabs
Help centre › LaTeX › Tables · Packages: booktabs
Load \usepackage{booktabs} and use \toprule at the top, \midrule under the header and \bottomrule at the end, with \cmidrule(lr){2-3} under grouped headings, and no vertical lines. booktabs gives the rules the right weights and space above and below them, which \hline lacks.
A complete example
A whole document: paste it into an empty project and compile it.
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Mean response time (ms) by condition.}\label{tab:rt}
\begin{tabular}{lrrrr}
\toprule
& \multicolumn{2}{c}{Session 1} & \multicolumn{2}{c}{Session 2} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
Condition & Mean & SD & Mean & SD \\
\midrule
Congruent & 512 & 48 & 498 & 45 \\
Incongruent & 587 & 61 & 560 & 57 \\
\addlinespace
Neutral & 530 & 52 & 515 & 50 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}The commands
\toprule,\midrule,\bottomrule: the top rule (heavier), the rule under the header (lighter), the bottom rule (heavier). Each takes an optional thickness, such as\toprule[1pt].\cmidrule(lr){2-3}: a rule under columns 2 to 3 only, under a grouped heading.(lr)trims both ends slightly so neighboring partial rules do not join;(l)or(r)trims one end.\addlinespace: a little vertical space between groups of rows, instead of another rule.\specialrule{1pt}{2pt}{2pt}: a rule of any thickness with any space above and below.
The rules of a good table
- No vertical lines. The columns' alignment separates them; vertical lines also break booktabs rules into pieces.
- Three horizontal rules are usually enough. Separate groups of rows with
\addlinespace, or a\midrulewhen the groups are truly different. - Units in the header ("Time (ms)"), not repeated in every cell.
- Numbers right-aligned or aligned on the decimal point, with the same number of decimals in a column.
- The caption above the table, which is the convention for tables in most styles.
Aligning numbers on the decimal point
The siunitx package's S column aligns numbers on their decimal point and can round them. Put text cells, such as headings, in braces so they are not read as numbers.
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{l S[table-format=2.3] S[table-format=1.2]}
\toprule
Parameter & {Estimate} & {SE} \\
\midrule
Intercept & 12.405 & 0.81 \\
Age & 0.32 & 0.04 \\
Dose & -1.7 & 0.33 \\
\bottomrule
\end{tabular}
\end{document}Common mistakes
- Mixing
\hlinewith booktabs rules, or vertical lines with them: the rules no longer meet, and the table looks broken. - Using
\clineinstead of\cmidrulein a booktabs table: the spacing does not match the other rules. - Colored rows (from
colortblorxcolor'stableoption) with booktabs: the space booktabs adds around rules is not colored, leaving white bands. Choose one or the other. - Rules on every row: the table looks like a grid again; use
\addlinespacefor grouping.
In journal templates
- Journals restyle tables at production, but a table with booktabs rules and no vertical lines is close to most house styles already. Some classes load booktabs themselves; loading it again in the preamble is harmless.
Errors you may meet
- Undefined control sequence.LaTeX met a command it does not know: usually a typo, or a command whose package is not loaded. The log's l. line ends with the culprit.
- Extra alignment tab has been changed to \cr.A table or matrix row has more & cells than the column specification allows. Add a column to {…}, remove an &, or add a missing \\.
- Misplaced alignment tab character &.An & appeared outside a table or align environment. In text write \&; in a bibliography fix the & in the .bib entry; in maths use align.
In Manulyx
Insert → Table puts a table environment in place, and pasting a range copied from a spreadsheet (two or more rows and columns) goes in as a LaTeX table, with booktabs rules when the paper loads booktabs and \hline otherwise; a notice offers the plain text back.
Write in Manulyx for free · Journal templates
Related
- Merge cells in a LaTeX table: multirow and multicolumnMerge table cells across columns with \multicolumn and across rows with \multirow (multirow package), with booktabs rules and \cline/\cmidrule.
- Make a LaTeX table fit the page widthFit a too-wide LaTeX table: tabularx X columns, p{} columns that wrap, a smaller font, less column spacing, and why \resizebox is a last resort.
- Table notes and footnotes in a LaTeX table (threeparttable)Add notes under a LaTeX table with markers in the cells, using threeparttable's \tnote and tablenotes, and why \footnote inside a table goes missing.
- A table across several pages in LaTeX (longtable)Break a long LaTeX table across pages with longtable, repeating the header on each page and adding a "continued" note, with booktabs rules.
- A landscape table or page in LaTeXTurn a wide table sideways: pdflscape's landscape environment rotates whole pages (upright on screen); rotating's sidewaystable rotates a float.
The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained