Let
X
Lesson 6 of 8

Tables: Building and Styling Tabular Data

~9 min read

By the end of this lesson you can build a table with aligned columns, add a caption and label, merge cells, and style it professionally with booktabs. Tables use the tabular environment; wrap it in table for a caption.

The tabular environment

Declare one alignment letter per column: l (left), c (center), r (right). A | adds a vertical line. Separate cells with &, end rows with \\, and draw horizontal lines with \hline.

\begin{tabular}{|l|c|r|}
  \hline
  Item & Qty & Price \\
  \hline
  Pen & 3 & 1.50 \\
  Notebook & 1 & 4.00 \\
  \hline
\end{tabular}

Adding a caption and label

Wrap the tabular in a table float to caption and reference it, just like a figure:

\begin{table}[ht]
  \centering
  \begin{tabular}{lcr}
    Item & Qty & Price \\
    Pen & 3 & 1.50
  \end{tabular}
  \caption{Order summary.}
  \label{tab:order}
\end{table}

See Table~\ref{tab:order}.

Professional style with booktabs

The academic standard is the booktabs package: no vertical lines, and three rule commands — \toprule, \midrule, \bottomrule. The result is far cleaner than \hline grids.

The recommended table style
\usepackage{booktabs}   % preamble
% ...
\begin{tabular}{lcr}
  \toprule
  Item & Qty & Price \\
  \midrule
  Pen & 3 & 1.50 \\
  Notebook & 1 & 4.00 \\
  \bottomrule
\end{tabular}

Spanning cells

  • Across columns: \multicolumn{2}{c}{Header} merges 2 columns, centered.
  • Across rows: load \usepackage{multirow} and use \multirow{2}{*}{Text}.

Wide tables that fit the page

If a table is too wide, use tabularx with an X column that auto-stretches to a target width:

\usepackage{tabularx}
% ...
\begin{tabularx}{\textwidth}{l X r}
  Name & Description (wraps to fit) & Value \\
\end{tabularx}

Writing tables by hand is tedious — many editors and spreadsheet exporters generate the tabular code for you. Paste it into LetX and tweak.

Frequently asked questions

What is the best table style in LaTeX?

The booktabs package: use \toprule, \midrule, \bottomrule and avoid vertical lines. It is the academic standard and looks far cleaner than \hline grids.

How do I merge cells?

Use \multicolumn{n}{align}{text} to span columns and the multirow package with \multirow{n}{*}{text} to span rows.

My table is wider than the page — how do I fix it?

Use tabularx with an X column to auto-fit to \textwidth, reduce column padding, shrink the font, or rotate the table with the rotating package.