Getting Started
Text Formatting
Mathematical Expressions
Document Structure
LaTeX Tables Tutorial
Tables are essential for presenting structured data in academic and professional documents. This comprehensive tutorial walks you through creating tables in LaTeX, from basic structures to advanced formatting.
Quick Tip: Use Our Table Generator
Don't want to write table code manually? Paste your Excel table data into our free tool and get instant LaTeX code.
Open Table Generator
Part 1: Basic Table Structure
LaTeX tables use the tabular environment. The basic syntax defines columns and their alignment:
\begin{tabular}{column specifications}
content
\end{tabular}Column Alignment Options
| Specifier | Meaning | Example |
|---|---|---|
l | Left-aligned column | Text, names |
c | Center-aligned column | Headers, short text |
r | Right-aligned column | Numbers |
| | Vertical line | Borders |
p{width} | Fixed width with wrapping | Long text |
Part 2: Your First Table
Let's create a simple 3-column table:
\begin{tabular}{lcc}
Name & Age & City \\
Alice & 25 & New York \\
Bob & 30 & Los Angeles \\
Charlie & 28 & Chicago
\end{tabular}Output:
| Name | Age | City |
| Alice | 25 | New York |
| Bob | 30 | Los Angeles |
| Charlie | 28 | Chicago |
Key syntax: Use & to separate columns and \\ to end rows.
Part 3: Adding Lines and Borders
Add horizontal lines with these commands:
\hline- Full horizontal line\cline{i-j}- Line spanning columns i to j|in column spec - Vertical line
\begin{tabular}{|l|c|r|}
\hline
Left & Center & Right \\
\hline
A & B & C \\
D & E & F \\
\hline
\end{tabular}| Left | Center | Right |
|---|---|---|
| A | B | C |
| D | E | F |
Part 4: Professional Tables with booktabs
For publication-quality tables, use the booktabs package. It provides cleaner horizontal rules without vertical lines:
\usepackage{booktabs}
\begin{tabular}{lrr}
\toprule
Item & Qty & Price \\
\midrule
Apples & 5 & \$2.50 \\
Oranges & 3 & \$1.80 \\
Bananas & 8 & \$3.20 \\
\midrule
Total & 16 & \$7.50 \\
\bottomrule
\end{tabular}| Item | Qty | Price |
|---|---|---|
| Apples | 5 | $2.50 |
| Oranges | 3 | $1.80 |
| Bananas | 8 | $3.20 |
| Total | 16 | $7.50 |
booktabs commands: \toprule (top), \midrule (middle), \bottomrule (bottom)
Part 5: Spanning Multiple Columns
Use \multicolumn to merge cells across columns:
\multicolumn{number of columns}{alignment}{content}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{3}{|c|}{Quarterly Sales Report} \\
\hline
Q1 & Q2 & Q3 \\
\hline
\$100k & \$150k & \$200k \\
\hline
\end{tabular}| Quarterly Sales Report | ||
|---|---|---|
| Q1 | Q2 | Q3 |
| $100k | $150k | $200k |
Part 6: Spanning Multiple Rows
Use the multirow package to merge cells vertically:
\usepackage{multirow}
\multirow{number of rows}{width}{content}
\begin{tabular}{|c|c|c|}
\hline
\multirow{2}{*}{Category} & Item A & 10 \\
& Item B & 20 \\
\hline
\end{tabular}Use * for automatic width, or specify like 2cm.
Part 7: Floating Tables with Captions
Wrap your tabular in a table environment for positioning and captions:
\begin{table}[htbp]
\centering
\caption{Experimental Results}
\label{tab:results}
\begin{tabular}{lcc}
\toprule
Method & Accuracy & Speed \\
\midrule
Method A & 95.2\% & Fast \\
Method B & 97.8\% & Slow \\
\bottomrule
\end{tabular}
\end{table}
As shown in Table~\ref{tab:results}, Method B is more accurate.Position options: h (here), t (top), b (bottom), p (separate page), ! (override)
Part 8: Fixed-Width Columns
For text that needs to wrap, use p{width}, m{width}, or b{width}:
| Specifier | Vertical Alignment |
|---|---|
p{2cm} | Top-aligned |
m{2cm} | Middle-aligned (requires array package) |
b{2cm} | Bottom-aligned (requires array package) |
\begin{tabular}{|l|p{5cm}|}
\hline
Term & Definition \\
\hline
LaTeX & A document preparation system for
high-quality typesetting \\
\hline
\end{tabular}Part 9: Full-Width Tables with tabularx
The tabularx package creates tables that span a specific width:
\usepackage{tabularx}
\begin{tabularx}{\textwidth}{|l|X|X|}
\hline
ID & Name & Description \\
\hline
1 & Item One & This column automatically
expands to fill space \\
2 & Item Two & The X column type handles
the expansion \\
\hline
\end{tabularx}The X column type expands to fill remaining space, distributing it equally among all X columns.
Part 10: Coloring Tables
Use the xcolor package with the table option for colored tables:
\usepackage[table]{xcolor}
\begin{tabular}{|l|c|c|}
\hline
\rowcolor{gray!30} Header 1 & Header 2 & Header 3 \\
\hline
Row 1 & Data & Data \\
\rowcolor{gray!10} Row 2 & Data & Data \\
Row 3 & Data & Data \\
\hline
\end{tabular}
% For alternating row colors:
\rowcolors{2}{gray!10}{white}
\begin{tabular}{lcc}
...
\end{tabular}Complete Example: Publication-Ready Table
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Comparison of Machine Learning Models}
\label{tab:ml-comparison}
\begin{tabular}{lSSS}
\toprule
Model & {Accuracy (\%)} & {F1 Score} & {Time (ms)} \\
\midrule
Random Forest & 94.5 & 0.932 & 145 \\
SVM & 92.1 & 0.915 & 89 \\
Neural Network & 96.8 & 0.961 & 234 \\
Gradient Boost & 95.2 & 0.948 & 178 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}The siunitx package with S columns automatically aligns decimal points.
Best Practices Checklist
- Use
booktabsfor professional-looking tables without vertical lines - Always include a caption and label for referenced tables
- Right-align numerical data for easy comparison
- Use
siunitxfor proper number formatting - Keep tables simple and avoid unnecessary borders
- Use
\centeringinstead of thecenterenvironment - Consider using
tabularxfor full-width tables
Essential Table Packages
\usepackage{booktabs} % Professional rules
\usepackage{multirow} % Span rows
\usepackage{tabularx} % Full-width tables
\usepackage{siunitx} % Number alignment
\usepackage[table]{xcolor} % ColorsLaTeX Tables Tutorial
Tables are essential for presenting structured data in academic and professional documents. This comprehensive tutorial walks you through creating tables in LaTeX, from basic structures to advanced formatting.
Quick Tip: Use Our Table Generator
Don't want to write table code manually? Paste your Excel table data into our free tool and get instant LaTeX code.
Open Table Generator
Part 1: Basic Table Structure
LaTeX tables use the tabular environment. The basic syntax defines columns and their alignment:
\begin{tabular}{column specifications}
content
\end{tabular}Column Alignment Options
| Specifier | Meaning | Example |
|---|---|---|
l | Left-aligned column | Text, names |
c | Center-aligned column | Headers, short text |
r | Right-aligned column | Numbers |
| | Vertical line | Borders |
p{width} | Fixed width with wrapping | Long text |
Part 2: Your First Table
Let's create a simple 3-column table:
\begin{tabular}{lcc}
Name & Age & City \\
Alice & 25 & New York \\
Bob & 30 & Los Angeles \\
Charlie & 28 & Chicago
\end{tabular}Output:
| Name | Age | City |
| Alice | 25 | New York |
| Bob | 30 | Los Angeles |
| Charlie | 28 | Chicago |
Key syntax: Use & to separate columns and \\ to end rows.
Part 3: Adding Lines and Borders
Add horizontal lines with these commands:
\hline- Full horizontal line\cline{i-j}- Line spanning columns i to j|in column spec - Vertical line
\begin{tabular}{|l|c|r|}
\hline
Left & Center & Right \\
\hline
A & B & C \\
D & E & F \\
\hline
\end{tabular}| Left | Center | Right |
|---|---|---|
| A | B | C |
| D | E | F |
Part 4: Professional Tables with booktabs
For publication-quality tables, use the booktabs package. It provides cleaner horizontal rules without vertical lines:
\usepackage{booktabs}
\begin{tabular}{lrr}
\toprule
Item & Qty & Price \\
\midrule
Apples & 5 & \$2.50 \\
Oranges & 3 & \$1.80 \\
Bananas & 8 & \$3.20 \\
\midrule
Total & 16 & \$7.50 \\
\bottomrule
\end{tabular}| Item | Qty | Price |
|---|---|---|
| Apples | 5 | $2.50 |
| Oranges | 3 | $1.80 |
| Bananas | 8 | $3.20 |
| Total | 16 | $7.50 |
booktabs commands: \toprule (top), \midrule (middle), \bottomrule (bottom)
Part 5: Spanning Multiple Columns
Use \multicolumn to merge cells across columns:
\multicolumn{number of columns}{alignment}{content}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{3}{|c|}{Quarterly Sales Report} \\
\hline
Q1 & Q2 & Q3 \\
\hline
\$100k & \$150k & \$200k \\
\hline
\end{tabular}| Quarterly Sales Report | ||
|---|---|---|
| Q1 | Q2 | Q3 |
| $100k | $150k | $200k |
Part 6: Spanning Multiple Rows
Use the multirow package to merge cells vertically:
\usepackage{multirow}
\multirow{number of rows}{width}{content}
\begin{tabular}{|c|c|c|}
\hline
\multirow{2}{*}{Category} & Item A & 10 \\
& Item B & 20 \\
\hline
\end{tabular}Use * for automatic width, or specify like 2cm.
Part 7: Floating Tables with Captions
Wrap your tabular in a table environment for positioning and captions:
\begin{table}[htbp]
\centering
\caption{Experimental Results}
\label{tab:results}
\begin{tabular}{lcc}
\toprule
Method & Accuracy & Speed \\
\midrule
Method A & 95.2\% & Fast \\
Method B & 97.8\% & Slow \\
\bottomrule
\end{tabular}
\end{table}
As shown in Table~\ref{tab:results}, Method B is more accurate.Position options: h (here), t (top), b (bottom), p (separate page), ! (override)
Part 8: Fixed-Width Columns
For text that needs to wrap, use p{width}, m{width}, or b{width}:
| Specifier | Vertical Alignment |
|---|---|
p{2cm} | Top-aligned |
m{2cm} | Middle-aligned (requires array package) |
b{2cm} | Bottom-aligned (requires array package) |
\begin{tabular}{|l|p{5cm}|}
\hline
Term & Definition \\
\hline
LaTeX & A document preparation system for
high-quality typesetting \\
\hline
\end{tabular}Part 9: Full-Width Tables with tabularx
The tabularx package creates tables that span a specific width:
\usepackage{tabularx}
\begin{tabularx}{\textwidth}{|l|X|X|}
\hline
ID & Name & Description \\
\hline
1 & Item One & This column automatically
expands to fill space \\
2 & Item Two & The X column type handles
the expansion \\
\hline
\end{tabularx}The X column type expands to fill remaining space, distributing it equally among all X columns.
Part 10: Coloring Tables
Use the xcolor package with the table option for colored tables:
\usepackage[table]{xcolor}
\begin{tabular}{|l|c|c|}
\hline
\rowcolor{gray!30} Header 1 & Header 2 & Header 3 \\
\hline
Row 1 & Data & Data \\
\rowcolor{gray!10} Row 2 & Data & Data \\
Row 3 & Data & Data \\
\hline
\end{tabular}
% For alternating row colors:
\rowcolors{2}{gray!10}{white}
\begin{tabular}{lcc}
...
\end{tabular}Complete Example: Publication-Ready Table
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Comparison of Machine Learning Models}
\label{tab:ml-comparison}
\begin{tabular}{lSSS}
\toprule
Model & {Accuracy (\%)} & {F1 Score} & {Time (ms)} \\
\midrule
Random Forest & 94.5 & 0.932 & 145 \\
SVM & 92.1 & 0.915 & 89 \\
Neural Network & 96.8 & 0.961 & 234 \\
Gradient Boost & 95.2 & 0.948 & 178 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}The siunitx package with S columns automatically aligns decimal points.
Best Practices Checklist
- Use
booktabsfor professional-looking tables without vertical lines - Always include a caption and label for referenced tables
- Right-align numerical data for easy comparison
- Use
siunitxfor proper number formatting - Keep tables simple and avoid unnecessary borders
- Use
\centeringinstead of thecenterenvironment - Consider using
tabularxfor full-width tables
Essential Table Packages
\usepackage{booktabs} % Professional rules
\usepackage{multirow} % Span rows
\usepackage{tabularx} % Full-width tables
\usepackage{siunitx} % Number alignment
\usepackage[table]{xcolor} % ColorsGetting Started
Text Formatting
Mathematical Expressions
Document Structure