Tables in LaTeX
The tabular environment lays out a table: its column list says how each column is aligned, & separates cells, and \\ ends each row.
LaTeX command
\begin{tabular}{|l|c|} \hline Name & Mark \\ \hline \end{tabular}Not the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
The column list is one letter per column: l left, c centre, r right, or p{4cm} for a column of fixed width whose text wraps. A | between letters draws a vertical line, and \hline draws a horizontal line across the table; \cline{2-3} draws one under some columns only.
\multicolumn{2}{c}{...} makes one cell span two columns, and the multirow package's \multirow{2}{*}{...} spans rows. For a numbered caption and a reference, put the tabular inside a table environment with \caption and \label; LaTeX then places it where it fits best.
Many publishers prefer tables without vertical lines, using the booktabs package's \toprule, \midrule and \bottomrule, which are spaced better than \hline. \renewcommand{\arraystretch}{1.3} gives every row more room.
A table with a caption
The table environment holds the caption and lets you refer to the table by number with \ref.
\begin{table}[h] \centering \begin{tabular}{lcc} Name & Test 1 & Test 2 \\ \hline Ada & 92 & 88 \end{tabular} \caption{Results} \label{tab:results} \end{table}Clean rules with booktabs
Load booktabs and use three rules instead of \hline and vertical lines.
\usepackage{booktabs}\toprule Name & Mark \\ \midrule Ada & 92 \\ \bottomruleOther forms
\multicolumn{2}{c}{Heading}a cell across two columns\multirow{2}{*}{Cell}a cell down two rows, multirow\toprule \midrule \bottomruleclean rules, booktabsp{4cm}a column of fixed width that wrapsExamples
$\begin{array}{|l|c|} \hline \text{Name} & \text{Mark} \\ \hline \text{Ada} & 92 \\ \text{Ben} & 85 \\ \hline \end{array}$a table with lines
$\begin{array}{lrr} \text{Item} & \text{Qty} & \text{Price} \\ \hline \text{Pens} & 3 & 1.50 \\ \text{Paper} & 10 & 4.00 \end{array}$numbers aligned right, one rule
$\begin{array}{c|ccc} \times & 1 & 2 & 3 \\ \hline 1 & 1 & 2 & 3 \\ 2 & 2 & 4 & 6 \end{array}$a times table
Tips and common mistakes
- Give the column list one letter per column, and the same number of cells in every row.
- Use p{width} for columns of text that should wrap.
- Put a captioned table in a table environment, with
\captionbefore\label. - Consider booktabs rules and no vertical lines for a cleaner table.
- Escape & in a cell as \&, since a bare & starts the next cell.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
How do I make a table in LaTeX?
Use tabular: \begin{tabular}{lcr} a & b & c \\ \end{tabular}, with & between cells and \\ after each row.
How do I add lines to a table?
Put | in the column list for vertical lines and \hline between rows for horizontal ones.
How do I merge cells?
Use \multicolumn{2}{c}{...} across columns, or \multirow{2}{*}{...} from the multirow package down rows.
How do I add a caption to a table?
Put the tabular inside \begin{table} ... \end{table} and add \caption{...}.