LaTeX Tables
Tables are essential for presenting structured data in academic papers, reports, and presentations. LaTeX provides a powerful set of tools for creating everything from simple data grids to complex, publication-quality tables with merged cells, colour, and multi-page support. This guide covers every technique you need.
Basic Table Structure
The foundation of every LaTeX table is the tabular environment. It takes a column specification that defines how many columns the table has and how each column is aligned. Cells in the same row are separated by &, and rows are terminated by \\. Horizontal lines are drawn with \hline.
\documentclass{article}
\begin{document}
\begin{tabular}{l c r}
\hline
Left & Centre & Right \\
\hline
A1 & B1 & C1 \\
A2 & B2 & C2 \\
A3 & B3 & C3 \\
\hline
\end{tabular}
\end{document}The column specifier {l c r} defines three columns: left-aligned, centred, and right-aligned respectively. Each & advances to the next column, and each \\\\ ends the current row.
The table Environment
The tabular environment creates the table content itself, but it does not make the table "float" or give it a caption. To add those features, wrap the tabular inside a table environment. The table environment is a floating container that LaTeX can position automatically for optimal page layout.
\begin{table}[htbp]
\centering
\caption{Experimental results for three samples.}
\label{tab:results}
\begin{tabular}{l c c}
\hline
Sample & Temperature (\textdegree C) & Yield (\%) \\
\hline
A & 100 & 85 \\
B & 150 & 92 \\
C & 200 & 78 \\
\hline
\end{tabular}
\end{table}Key elements of the table environment:
\centering– Centres the table horizontally on the page.\caption{...}– Adds a numbered caption. Place it above or below the tabular.\label{tab:results}– Creates a reference label so you can use\ref{tab:results}elsewhere.[htbp]– Placement specifiers: here,top, bottom, page of floats. LaTeX tries each in order.
Column Alignment
The column specifier string controls alignment and structure. LaTeX provides several column types out of the box:
| Specifier | Alignment | Description |
|---|---|---|
l | Left | Left-aligned column, natural width |
c | Centre | Centre-aligned column, natural width |
r | Right | Right-aligned column, natural width |
p{width} | Top | Paragraph column with specified width, top-aligned |
m{width} | Middle | Paragraph column, vertically centred (requires array package) |
b{width} | Bottom | Paragraph column, bottom-aligned (requires array package) |
% Paragraph columns are useful for wrapping long text
\begin{tabular}{l p{5cm} r}
\hline
Name & Description & Score \\
\hline
Alpha & A long description that wraps within the
specified 5cm column width. & 95 \\
Beta & Another description, also wrapped. & 88 \\
\hline
\end{tabular}You can also add vertical lines between columns by placing | in the column specifier, although modern typographic practice discourages heavy use of vertical rules:
% Vertical lines (old style — prefer booktabs instead)
\begin{tabular}{|l|c|r|}
\hline
Left & Centre & Right \\
\hline
A & B & C \\
\hline
\end{tabular}Adding Lines and Rules
LaTeX provides several ways to add horizontal and partial lines to tables. The built-in commands work but produce results that are typographically inferior to thebooktabs package.
Basic Lines
% \hline draws a full-width horizontal line
\begin{tabular}{l c r}
\hline
Header 1 & Header 2 & Header 3 \\
\hline
A & B & C \\
D & E & F \\
\hline
\end{tabular}
% \cline{i-j} draws a partial line from column i to column j
\begin{tabular}{l c r}
\hline
Header 1 & Header 2 & Header 3 \\
\cline{1-2}
A & B & C \\
\cline{2-3}
D & E & F \\
\hline
\end{tabular}The booktabs Package
The booktabs package provides three commands that produce cleaner, more professional rules with proper spacing:
\toprule– A thick line at the top of the table\midrule– A thinner line separating the header from the body\bottomrule– A thick line at the bottom of the table
\usepackage{booktabs}
\begin{tabular}{l c r}
\toprule
Header 1 & Header 2 & Header 3 \\
\midrule
A & B & C \\
D & E & F \\
G & H & I \\
\bottomrule
\end{tabular}Professional Tables with booktabs
The booktabs package is the gold standard for typesetting tables in LaTeX. It follows a key principle: never use vertical rules andnever use double rules. Compare the two approaches:
Before: Traditional Style
% Old-fashioned table with vertical and double lines
\begin{tabular}{|l|c|r|}
\hline\hline
Name & Grade & Score \\
\hline\hline
Alice & A & 95 \\
\hline
Bob & B+ & 88 \\
\hline
Carol & A- & 91 \\
\hline\hline
\end{tabular}After: booktabs Style
% Clean, professional table with booktabs
\usepackage{booktabs}
\begin{tabular}{lcr}
\toprule
Name & Grade & Score \\
\midrule
Alice & A & 95 \\
Bob & B+ & 88 \\
Carol & A- & 91 \\
\bottomrule
\end{tabular}The booktabs version is cleaner, more readable, and matches the style used in most published journals. The booktabs package also provides\cmidrule{i-j} for partial horizontal rules with proper trimming:
\begin{tabular}{lcc}
\toprule
& \multicolumn{2}{c}{Scores} \\
\cmidrule(lr){2-3}
Student & Midterm & Final \\
\midrule
Alice & 92 & 95 \\
Bob & 85 & 88 \\
Carol & 90 & 91 \\
\bottomrule
\end{tabular}The (lr) after \cmidrule trims the rule slightly on the left and right, creating visual separation between column groups. You can use(l), (r), or (lr) as needed.
Multi-Column Cells
The \multicolumn command allows a single cell to span multiple columns. This is commonly used for group headers or merged cells:
\multicolumn{number_of_columns}{alignment}{text}\usepackage{booktabs}
\begin{tabular}{lccc}
\toprule
\multicolumn{1}{l}{Name} & \multicolumn{3}{c}{Scores} \\
\cmidrule(lr){2-4}
& Math & Science & English \\
\midrule
Alice & 95 & 92 & 88 \\
Bob & 82 & 90 & 95 \\
Carol & 91 & 88 & 84 \\
\bottomrule
\end{tabular}The first argument is the number of columns to span, the second is the alignment specifier for the merged cell (e.g., c, l, r), and the third is the cell content. You can also use \multicolumn{1}to override the alignment of a single cell.
Multi-Row Cells
The multirow package provides the \multirow command for cells that span multiple rows:
\multirow{number_of_rows}{width}{text}\usepackage{booktabs}
\usepackage{multirow}
\begin{tabular}{llc}
\toprule
Category & Item & Price \\
\midrule
\multirow{2}{*}{Fruit}
& Apple & \$1.20 \\
& Banana & \$0.80 \\
\midrule
\multirow{3}{*}{Vegetable}
& Carrot & \$0.90 \\
& Potato & \$1.10 \\
& Onion & \$0.70 \\
\bottomrule
\end{tabular}The * for the width argument tells LaTeX to use the natural width of the text. You can also specify an explicit width like 2cm if needed.
Table Width Control
By default, LaTeX tables are only as wide as their content requires. To make a table span the full text width (or any specific width), use the tabularx package.
Using tabularx
\usepackage{tabularx}
% Syntax: \begin{tabularx}{width}{column spec}
% The X column type stretches to fill available space
\begin{tabularx}{\textwidth}{l X r}
\toprule
Name & Description & Score \\
\midrule
Alpha & This column stretches to fill the remaining
width of the table. & 95 \\
Beta & The X column type distributes space evenly. & 88 \\
\bottomrule
\end{tabularx}You can use multiple X columns, and the available space is divided equally among them:
\begin{tabularx}{\textwidth}{l X X}
\toprule
ID & Title & Description \\
\midrule
1 & First item & Detailed info \\
2 & Second item & More details here \\
\bottomrule
\end{tabularx}Full-Width Tables in Two-Column Documents
If your document uses a two-column layout, use the table* environment to create a table that spans both columns:
\documentclass[twocolumn]{article}
\usepackage{booktabs}
\begin{document}
% This table spans both columns
\begin{table*}[t]
\centering
\caption{Results across all experiments.}
\begin{tabular}{lcccccc}
\toprule
Method & Exp 1 & Exp 2 & Exp 3 & Exp 4 & Exp 5 & Average \\
\midrule
Ours & 95.2 & 93.1 & 94.8 & 96.0 & 92.7 & 94.4 \\
Base & 90.1 & 88.5 & 89.3 & 91.2 & 87.6 & 89.3 \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}Long Tables
Standard LaTeX tables cannot break across pages. If your table is longer than a single page, use the longtable package. It automatically breaks the table across pages and can repeat headers and footers on each page.
\usepackage{longtable}
\usepackage{booktabs}
\begin{longtable}{lcc}
% First header (appears on the first page)
\caption{Complete list of experimental results.}
\label{tab:longresults} \\
\toprule
Experiment & Temperature (\textdegree C) & Yield (\%) \\
\midrule
\endfirsthead
% Continuation header (appears on subsequent pages)
\multicolumn{3}{c}{\textit{Continued from previous page}} \\
\toprule
Experiment & Temperature (\textdegree C) & Yield (\%) \\
\midrule
\endhead
% Footer on every page except the last
\midrule
\multicolumn{3}{r}{\textit{Continued on next page}} \\
\endfoot
% Footer on the last page
\bottomrule
\endlastfoot
% Table body
Trial 1 & 100 & 85 \\
Trial 2 & 110 & 87 \\
Trial 3 & 120 & 90 \\
Trial 4 & 130 & 88 \\
Trial 5 & 140 & 91 \\
Trial 6 & 150 & 93 \\
Trial 7 & 160 & 89 \\
Trial 8 & 170 & 86 \\
Trial 9 & 180 & 82 \\
Trial 10 & 190 & 79 \\
% ... more rows as needed
\end{longtable}The four sectioning commands control what appears where:
\endfirsthead– Marks the end of the header for the first page\endhead– Marks the end of the header for continuation pages\endfoot– Marks the end of the footer for all pages except the last\endlastfoot– Marks the end of the footer for the final page
Colored Tables
The xcolor package (with the table option) and thecolortbl package let you add background colours to rows, columns, and individual cells.
\usepackage[table]{xcolor}
% or: \usepackage{colortbl}
% Define custom colours
\definecolor{headerblue}{RGB}{0, 102, 204}
\definecolor{lightgray}{gray}{0.9}
\definecolor{lightblue}{RGB}{220, 235, 255}Row Colours
\usepackage[table]{xcolor}
\usepackage{booktabs}
\begin{tabular}{lcc}
\toprule
\rowcolor{headerblue}
\textcolor{white}{Name} &
\textcolor{white}{Grade} &
\textcolor{white}{Score} \\
\midrule
\rowcolor{lightgray}
Alice & A & 95 \\
Bob & B+ & 88 \\
\rowcolor{lightgray}
Carol & A- & 91 \\
Dave & B & 84 \\
\bottomrule
\end{tabular}Alternating Row Colours
\usepackage[table]{xcolor}
% Automatically alternate row colours
\rowcolors{2}{lightgray}{white}
\begin{tabular}{lcc}
\toprule
Name & Grade & Score \\
\midrule
Alice & A & 95 \\
Bob & B+ & 88 \\
Carol & A- & 91 \\
Dave & B & 84 \\
Eve & A+ & 98 \\
\bottomrule
\end{tabular}Cell Colours
\usepackage[table]{xcolor}
\begin{tabular}{lcc}
\toprule
Name & Status & Score \\
\midrule
Alice & \cellcolor{green!25}Pass & 95 \\
Bob & \cellcolor{red!25}Fail & 42 \\
Carol & \cellcolor{green!25}Pass & 91 \\
Dave & \cellcolor{yellow!25}Borderline & 60 \\
\bottomrule
\end{tabular}Column Colours
\usepackage[table]{xcolor}
\usepackage{array}
% Apply colour to an entire column using the > directive
\begin{tabular}{l >{columncolor{lightblue}}c c}
\toprule
Name & Highlighted & Normal \\
\midrule
Alice & 95 & A \\
Bob & 88 & B+ \\
Carol & 91 & A- \\
\bottomrule
\end{tabular}Merging Rows and Columns Together
For complex table layouts, you can combine \multicolumn and\multirow in the same table. This is common in academic papers where you need hierarchical headers or grouped data.
\usepackage{booktabs}
\usepackage{multirow}
\begin{tabular}{llccc}
\toprule
\multirow{2}{*}{Department} &
\multirow{2}{*}{Employee} &
\multicolumn{3}{c}{Quarterly Sales (\$k)} \\
\cmidrule(lr){3-5}
& & Q1 & Q2 & Q3 \\
\midrule
\multirow{3}{*}{Engineering}
& Alice & 120 & 135 & 142 \\
& Bob & 98 & 110 & 105 \\
& Carol & 115 & 128 & 138 \\
\midrule
\multirow{2}{*}{Marketing}
& Dave & 200 & 220 & 245 \\
& Eve & 180 & 195 & 210 \\
\bottomrule
\end{tabular}When combining these commands, remember that:
\multicolumntakes effect on a single row and merges cells horizontally.\multirowtakes effect starting from the current row and merges cells vertically.- In the rows spanned by
\multirow, leave the corresponding cell empty (just use&to skip it).
Table Captions and Labels
Captions and labels are essential for numbered tables and cross-references. The\caption command generates a numbered caption (e.g., "Table 1: ..."), and \label creates a reference anchor.
Caption Placement
In most style guides, the caption for a table goes above the table (unlike figures, where captions typically go below). This is because readers scan a caption before reading the table data:
\begin{table}[htbp]
\centering
\caption{Summary of experimental results.}
\label{tab:summary}
\begin{tabular}{lcc}
\toprule
Method & Accuracy & F1 Score \\
\midrule
Ours & 94.5 & 93.2 \\
Base & 89.1 & 87.8 \\
\bottomrule
\end{tabular}
\end{table}Cross-Referencing Tables
Once you have labelled a table, you can refer to it anywhere in the document:
As shown in Table~\ref{tab:summary}, our method
outperforms the baseline by 5.4 percentage points.
% Use \pageref for the page number
The full results are in Table~\ref{tab:summary}
on page~\pageref{tab:summary}.Always place \label after \caption, not before. If you place it before the caption, the reference number may be incorrect.
Useful Packages for Tables
Here is a summary of the most important packages for LaTeX tables and what each one provides:
| Package | Purpose | Key Commands |
|---|---|---|
booktabs | Professional horizontal rules | \toprule, \midrule, \bottomrule, \cmidrule |
multirow | Cells spanning multiple rows | \multirow{rows}{width}{text} |
tabularx | Tables with automatic-width columns | X column type, \begin{tabularx}{width} |
longtable | Tables spanning multiple pages | \endfirsthead, \endhead, \endfoot, \endlastfoot |
colortbl | Coloured rows, columns, and cells | \rowcolor, \cellcolor, \columncolor |
siunitx | Align numbers by decimal point | S column type |
array | Extended column specifiers | m{}, b{}, >{}, <{} directives |
A typical preamble for a document with professional tables looks like this:
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{array}Quick Reference
A handy reference table for column types and common commands:
| Column Type | Alignment | Package | Description |
|---|---|---|---|
l | Left | Built-in | Left-aligned, natural width |
c | Centre | Built-in | Centre-aligned, natural width |
r | Right | Built-in | Right-aligned, natural width |
p{width} | Top | Built-in | Paragraph column, top-aligned |
m{width} | Middle | array | Paragraph column, vertically centred |
b{width} | Bottom | array | Paragraph column, bottom-aligned |
X | Justified | tabularx | Stretches to fill available width |
S | Decimal | siunitx | Aligns numbers by decimal point |
Common table commands at a glance:
| Command | Package | Description |
|---|---|---|
\hline | Built-in | Full-width horizontal line |
\cline{i-j} | Built-in | Partial horizontal line from column i to j |
\toprule | booktabs | Thick top rule |
\midrule | booktabs | Thin middle rule |
\bottomrule | booktabs | Thick bottom rule |
\cmidrule{i-j} | booktabs | Partial rule with optional trimming |
\multicolumn{n}{align}{text} | Built-in | Merge n columns into one cell |
\multirow{n}{width}{text} | multirow | Merge n rows into one cell |
\rowcolor{color} | colortbl / xcolor | Set background colour for a row |
\cellcolor{color} | colortbl / xcolor | Set background colour for a cell |
\columncolor{color} | colortbl / xcolor | Set background colour for a column |
Next Steps
Now that you can create professional tables in LaTeX, explore more topics:
- LaTeX Lists – Create ordered, unordered, and description lists
- Page Size & Margins – Control page layout with the geometry package
- Learn LaTeX – Complete beginner tutorial covering all the basics
- Learn TikZ – Create diagrams and graphics programmatically
- Learn PGFPlots – Generate publication-quality plots and charts
Free LaTeX Tools
Building tables by hand can be tedious. Use our free tools to speed up your workflow:
- Table to LaTeX Converter – Paste data from Excel, Google Sheets, or CSV and instantly get LaTeX table code with booktabs formatting
- LaTeX Preview – Test your LaTeX code with live PDF preview
- Math to LaTeX – Convert handwritten equations to LaTeX
- Citation Generator – Generate BibTeX citations from DOIs
- AI LaTeX Generator – Generate LaTeX from text descriptions
- LaTeX Symbols Reference – Browse math operators and Greek letters
Ready to start writing?
Try Octree – the AI-powered LaTeX editor that makes writing faster and easier.
Try Octree Free →