Tables in LaTeX: A Complete Guide
Tables are one of the most powerful — and most complained-about — parts of LaTeX. Once you understand the underlying logic, they become straightforward. This guide covers everything from a basic two-column table to spanning cells, professional styling, and tables that span multiple pages.
Basic Table Anatomy
Every LaTeX table involves two layers: the table float environment (handles positioning and captions) and the tabular environment (defines the actual rows and columns).
\begin{table}[htbp] % float: here, top, bottom, page
\centering
\caption{My first table}
\label{tab:first}
\begin{tabular}{lcc} % column spec: left, center, center
\hline
Name & Score & Grade \\
\hline
Alice & 92 & A \\
Bob & 78 & B+ \\
Charlie & 85 & A- \\
\hline
\end{tabular}
\end{table}The column spec lcc means: first column left-aligned, second and third centred. Use r for right-aligned. Each row ends with \\ and columns are separated by &.
Column Spec Reference
| Specifier | Meaning |
|---|---|
| l | Left-aligned column |
| c | Centred column |
| r | Right-aligned column |
| p{3cm} | Paragraph column with fixed width (wraps text) |
| | | Vertical rule between columns |
| @{} | Remove inter-column space |
| @{text} | Insert text/space between columns |
Professional Tables with booktabs
The booktabs package replaces the heavy \hline rules with lightweight, typographically correct rules. This is the standard in all serious academic publishing.
\usepackage{booktabs} % in preamble
\begin{table}[htbp]
\centering
\caption{Comparison of algorithms}
\label{tab:algo}
\begin{tabular}{lccc}
\toprule
Algorithm & Precision & Recall & F\textsubscript{1} \\
\midrule
Baseline & 0.82 & 0.79 & 0.80 \\
Method A & 0.87 & 0.83 & 0.85 \\
Ours & 0.91 & 0.88 & 0.89 \\
\bottomrule
\end{tabular}
\end{table}\topruleHeavy rule at the very top of the table\midruleMedium rule separating header from body\bottomruleHeavy rule at the very bottom\cmidrule{2-4}Partial rule spanning only columns 2–4Spanning Cells: multicolumn and multirow
\usepackage{multirow} % for multirow
\begin{tabular}{lccc}
\toprule
% multicolumn: span 3 cols, centred, text "Scores"
& \multicolumn{3}{c}{Scores} \\
\cmidrule{2-4}
Student & Math & Science & English \\
\midrule
% multirow: span 2 rows, text "Alice"
\multirow{2}{*}{Alice} & 90 & 85 & 92 \\
& 88 & 91 & 87 \\ % second row, same student
\midrule
Bob & 76 & 80 & 74 \\
\bottomrule
\end{tabular}\multicolumn{n}{spec}{text} spans n columns. \multirow{n}{width}{text} spans n rows — use * for automatic width.
Fixed-Width Columns and Text Wrapping
Long text in a table cell overflows unless you use a p{width} column, which sets a fixed width and wraps the text automatically.
\begin{tabular}{lp{6cm}}
\toprule
Package & Description \\
\midrule
amsmath & Provides advanced math environments including
align, gather, multline, and cases. \\
graphicx & Includes images with \includegraphics.
Supports scaling and rotation. \\
\bottomrule
\end{tabular}Tables Spanning Multiple Pages
Regular tabular cannot break across pages. Use the longtable package for tables that span multiple pages and need a repeated header.
\usepackage{longtable}
\begin{longtable}{lcc}
\caption{A very long table} \label{tab:long} \\
\toprule
Name & Score & Grade \\
\midrule
\endfirsthead % end of first-page header
\toprule
Name & Score & Grade \\
\midrule
\endhead % repeated header on subsequent pages
\bottomrule
\endlastfoot % footer on the last page only
Alice & 92 & A \\
Bob & 78 & B+ \\
% ... many more rows ...
\end{longtable}Build your tables in the editor
Paste any example above into Skozin and see the table rendered as a PDF instantly.
Start Writing