Underleaf Logo
Underleaf
PricingBlogInstall for OverleafGet Started

Learn LaTeX

Getting Started

  • What is LaTeX?
  • LaTeX for Beginners

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.

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

SpecifierMeaningExample
lLeft-aligned columnText, names
cCenter-aligned columnHeaders, short text
rRight-aligned columnNumbers
|Vertical lineBorders
p{width}Fixed width with wrappingLong 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:

NameAgeCity
Alice25New York
Bob30Los Angeles
Charlie28Chicago

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}
LeftCenterRight
ABC
DEF

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}
ItemQtyPrice
Apples5$2.50
Oranges3$1.80
Bananas8$3.20
Total16$7.50

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
Q1Q2Q3
$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}:

SpecifierVertical 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 booktabs for professional-looking tables without vertical lines
  • Always include a caption and label for referenced tables
  • Right-align numerical data for easy comparison
  • Use siunitx for proper number formatting
  • Keep tables simple and avoid unnecessary borders
  • Use \centering instead of the center environment
  • Consider using tabularx for full-width tables

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.

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

SpecifierMeaningExample
lLeft-aligned columnText, names
cCenter-aligned columnHeaders, short text
rRight-aligned columnNumbers
|Vertical lineBorders
p{width}Fixed width with wrappingLong 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:

NameAgeCity
Alice25New York
Bob30Los Angeles
Charlie28Chicago

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}
LeftCenterRight
ABC
DEF

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}
ItemQtyPrice
Apples5$2.50
Oranges3$1.80
Bananas8$3.20
Total16$7.50

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
Q1Q2Q3
$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}:

SpecifierVertical 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 booktabs for professional-looking tables without vertical lines
  • Always include a caption and label for referenced tables
  • Right-align numerical data for easy comparison
  • Use siunitx for proper number formatting
  • Keep tables simple and avoid unnecessary borders
  • Use \centering instead of the center environment
  • Consider using tabularx for full-width tables
Underleaf Logo
Underleaf

Empowering students and researchers with AI-powered tools for academic writing.

Go to app

Company

PricingBlogLearnAffiliate Program

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXThesis Statement GeneratorOverleaf Chrome ExtensionAll Tools

© 2025 Underleaf. All rights reserved.