How do you create a table in LaTeX?
A LaTeX table is built with the tabular environment. You declare one letter per column, separate cells with &, and end each row with \\. Wrap it in a table float to add a caption and a label you can reference. Load booktabs for publication quality rules instead of \hline.
Nilesh Arnaiya9 min
All snippets compiled with pdfLaTeX on 2026-10-20.
The minimal table that always compiles
Start here. Three columns, left, centre and right aligned.
\begin{tabular}{l c r}
Item & Qty & Price \\
\hline
Pipette tips & 12 & 48.00 \\
Slides & 200 & 15.50 \\
\end{tabular}Three rules cover ninety percent of table errors:
- The number of
&in a row is always one less than the number of column letters. - Every row ends with
\\except, optionally, the last one. tabularhas no caption and no number. That comes from thetablefloat, covered below.
Column types and alignment
| Type | Behaviour |
|---|---|
l c r | Left, centre, right aligned. Width fits the content. |
p{3cm} | Fixed width, text wraps, top aligned. |
m{3cm} | Fixed width, vertically centred. Needs array. |
b{3cm} | Fixed width, bottom aligned. Needs array. |
X | Absorbs remaining width. Needs tabularx. |
S | Aligns numbers on the decimal point. Needs siunitx. |
| | Vertical rule. Avoid it, see below. |
Use p{} the moment a cell contains a sentence, otherwise the column stretches off the page.
\usepackage{array}
\begin{tabular}{l p{5cm} r}
\toprule
Method & Description & $n$ \\
\midrule
Kilosort4 & Template matching on the GPU, fast but sensitive to drift. & 24 \\
MountainSort & Density based clustering, slower on long recordings. & 18 \\
\bottomrule
\end{tabular}For numeric results columns, align on the decimal point with siunitx. Header text in an S column has to be wrapped in braces.
\usepackage{siunitx}
\begin{tabular}{l S[table-format=2.2] S[table-format=1.3]}
\toprule
{Condition} & {Mean (Hz)} & {SD} \\
\midrule
Control & 4.20 & 0.317 \\
Treated & 11.08 & 1.240 \\
\bottomrule
\end{tabular}Publication quality rules with booktabs
\hline and vertical bars make a table look like a spreadsheet. Journals do not want that. booktabs gives you three rules with correct spacing baked in, and nothing else.
\usepackage{booktabs}
\begin{tabular}{lcr}
\toprule
Item & Qty & Price \\
\midrule
Pipette tips & 12 & 48.00 \\
Slides & 200 & 15.50 \\
\bottomrule
\end{tabular}Rules of thumb that match the booktabs manual: never use vertical rules, never use double rules, and use \cmidrule(lr){2-3} when you need a partial rule under a spanning header. The (lr) trims the rule so it does not touch neighbouring columns.
Merging cells: multicolumn and multirow
\multicolumn{n}{align}{text} merges horizontally and counts as n columns. \multirow{n}{*}{text} merges vertically and leaves the cells below it empty.
\usepackage{multirow}
\usepackage{booktabs}
\begin{tabular}{llr}
\toprule
\multicolumn{2}{c}{Sample} & \multirow{2}{*}{$n$} \\
\cmidrule(lr){1-2}
Group & Condition & \\
\midrule
A & Control & 24 \\
A & Treated & 22 \\
B & Control & 19 \\
\bottomrule
\end{tabular}The second row ends with & \\ because the third cell is already occupied by the \multirow above it. Forgetting that empty cell is the most common cause of Extra alignment tab has been changed to \cr.
Tables that are too wide
Three fixes, in order of preference.
1. tabularx, the correct fix.
The X column soaks up whatever width is left over.
\usepackage{tabularx}
\begin{tabularx}{\textwidth}{l X r}
\toprule
Tool & What it does & Year \\
\midrule
DeepLabCut & Markerless pose estimation for animal behaviour video, built on transfer learning. & 2018 \\
SpikeInterface & Unified API for running and comparing spike sorters. & 2020 \\
\bottomrule
\end{tabularx}2. Shrink the type.
Put \small or \footnotesize inside the float, before \begin{tabular}. Most journals allow a smaller size in tables than in body text.
3. \resizebox, the last resort.
It scales the font too, so your 10pt table becomes 7.4pt and the rules get thinner. Acceptable for a dense numeric table, wrong for anything with prose.
\usepackage{graphicx}
\resizebox{\textwidth}{!}{%
\begin{tabular}{lcccccc}
\toprule
Model & Acc & P & R & F1 & Params & FLOPs \\
\midrule
Baseline & 0.81 & 0.79 & 0.83 & 0.81 & 12M & 4.1G \\
\bottomrule
\end{tabular}%
}The trailing % on both lines matters. Without it you get a stray space inside the box.
In a two column document such as an IEEE or ACM submission, a table that will not fit one column goes in table* instead of table. A table* float can only be placed at the top of a page, so [!t] is the only placement worth passing.
Captions, labels and references
The caption and the number come from the table float, not from tabular. Convention in almost every style guide is caption above the table, unlike figures where it goes below.
\begin{table}[htbp]
\centering
\caption{Firing rates by condition.}
\label{tab:rates}
\begin{tabular}{lrr}
\toprule
Condition & Mean (Hz) & SD \\
\midrule
Control & 4.20 & 0.32 \\
Treated & 11.08 & 1.24 \\
\bottomrule
\end{tabular}
\end{table}
As shown in Table~\ref{tab:rates}, the treated group fired faster.Order matters: \label must come after \caption, or the reference resolves to the wrong number. Use ~ before \ref so the word and the number never split across a line break.
Tables that span multiple pages
table floats cannot break across pages. longtable can, and it is not a float, so it appears exactly where you put it.
\usepackage{longtable}
\usepackage{booktabs}
\begin{longtable}{lcr}
\caption{Recording sessions across all subjects.}
\label{tab:sessions} \\
\toprule
Subject & Sessions & Units \\
\midrule
\endfirsthead
\multicolumn{3}{c}{\tablename\ \thetable{} -- continued from previous page} \\
\toprule
Subject & Sessions & Units \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{Continued on next page} \\
\endfoot
\bottomrule
\endlastfoot
M01 & 12 & 318 \\
M02 & 9 & 274 \\
M03 & 14 & 402 \\
\end{longtable}\endfirsthead is the header on page one, \endhead repeats on every later page, \endfoot is the footer on every page but the last, \endlastfoot closes the table. Note the \\ after \label, it is required there and nowhere else.
longtable recalculates column widths on each run, so expect Table widths have changed. Rerun LaTeX. on the first compile. It clears on the second pass.
For a table that is too wide rather than too long, rotate it:
\usepackage{rotating}
\begin{sidewaystable}
\centering
\caption{Full model comparison across all benchmarks.}
\begin{tabular}{lcccc}
\toprule
A & B & C & D & E \\
\midrule
1 & 2 & 3 & 4 & 5 \\
\bottomrule
\end{tabular}
\end{sidewaystable}Footnotes inside tables
A plain \footnote inside a float silently disappears. Use threeparttable instead, which keeps the note attached to the table and aligned to its width.
\usepackage{threeparttable}
\begin{table}[htbp]
\centering
\begin{threeparttable}
\caption{Model comparison.}
\begin{tabular}{lrr}
\toprule
Model & Accuracy & Params \\
\midrule
Baseline & 0.81\tnote{a} & 12M \\
Ours & 0.89 & 14M \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item[a] Averaged over five seeds.
\end{tablenotes}
\end{threeparttable}
\end{table}Row shading and cell colour
Load xcolor with the table option, which pulls in colortbl.
\usepackage[table]{xcolor}
\rowcolors{2}{gray!10}{white} % start at row 2, alternate grey and white
\begin{tabular}{lrr}
\toprule
Condition & Mean & SD \\
\midrule
Control & 4.20 & 0.32 \\
Treated & 11.08 & 1.24 \\
Washout & 5.01 & 0.44 \\
\bottomrule
\end{tabular}For a single cell, \cellcolor{yellow!25} at the start of the cell content. Check the journal first, several camera ready templates forbid colour in tables because they still print in greyscale.
Common table errors and what causes them
| Error | Cause | Fix |
|---|---|---|
Extra alignment tab has been changed to \cr | More & in a row than the preamble allows, often a \multirow cell you forgot to leave empty | Count cells against the column letters |
Undefined control sequence \toprule | booktabs not loaded | \usepackage{booktabs} |
Misplaced \noalign | \hline or \midrule placed after a cell instead of after \\ | Move the rule onto its own line |
\begin{tabular} ended by \end{document} | Missing \end{tabular} | Match every \begin |
Underfull \hbox in a p{} column | LaTeX cannot justify a narrow column | Add \raggedright to the column via array, or widen it |
| Blank row before the bottom rule | A trailing \\ on the final data row | Drop the final \\ |
| Table floats pages away | table is a float and LaTeX found no legal spot | [htbp], or \FloatBarrier from placeins |
Float(s) lost | Too many unplaced floats queued | Force them out with \clearpage |
Importing data instead of typing it
Pasting numbers by hand means they go stale the moment you rerun the analysis. Read the CSV at compile time:
\usepackage{csvsimple}
\usepackage{booktabs}
\begin{tabular}{lrr}
\toprule
Subject & Sessions & Units \\
\midrule
\csvreader[late after line=\\]{sessions.csv}{subject=\subj,sessions=\sess,units=\units}%
{\subj & \sess & \units}
\bottomrule
\end{tabular}pgfplotstable does the same with more formatting control, including rounding and column styling.
Journal specific notes
- IEEE (
IEEEtran): captions above,table*with[!t]for full width, and the template expects\renewcommand{\arraystretch}{1.3}for readable row spacing. - Elsevier (
elsarticle): captions above, tables collected at the end of the manuscript for the review version unless the journal says otherwise. - ACM (
acmart):booktabsis loaded for you, and the class warns if you use\hline. - Springer (
sn-jnl): table notes go intablenotes, not footnotes.
Ready made, compiling versions of all four are in the Bibby template gallery.
Common questions
How do I center a table in LaTeX?
Put \centering immediately after \begin{table} and before the tabular environment. Do not use the center environment inside a float, it adds unwanted vertical space.
How do I make a LaTeX table fit the page width?
Use tabularx with an X column, which absorbs the leftover width. Only fall back to \resizebox when the table is numeric and dense, because it scales the font along with the table.
Why does my table appear on a different page?
table is a float, so LaTeX moves it to wherever it fits. Use [htbp] to widen the options and \FloatBarrier from the placeins package to stop it crossing a section boundary.
Should I use vertical lines in LaTeX tables?
No. Almost every journal style and the booktabs documentation recommend horizontal rules only, using \toprule, \midrule and \bottomrule, with whitespace doing the column separation.
How do I reference a table in LaTeX?
Put \label right after \caption, then cite it with Table~\ref{tab:name}. The tilde is a non-breaking space so the number never wraps onto the next line.
How do I convert an Excel sheet or CSV into a LaTeX table?
Use the csvsimple or pgfplotstable package to read the file directly at compile time, so the table updates when the data does, instead of pasting values by hand.