Table across multiple pages in LaTeX (longtable)

A tabular never breaks across pages. The longtable environment from the package of the same name does: it breaks between rows and can repeat the header on every page.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{longtable}
\usepackage{booktabs}

Replace table and tabular with longtable

longtable takes the same column argument as tabular and stands in the text without a table environment around it. \caption and \label go inside, and the caption line ends with \\.

\begin{longtable}{lr}
\caption{Measurements}
\label{tab:measurements} \\
\toprule
Sample & Value \\
\midrule
1 & 0.82 \\
2 & 0.91 \\
3 & 0.77 \\
\bottomrule
\end{longtable}
Result
The compiled example

Open in the editor

Repeat the header on every page

Four commands mark the repeated parts. The rows before \endfirsthead form the header of the first page, the rows up to \endhead the header of all following pages, the rows up to \endfoot the foot of every page except the last, and the rows up to \endlastfoot the foot of the last page. The data rows follow.

\begin{longtable}{lr}
\caption{Measurements} \\
\toprule
Sample & Value \\
\midrule
\endfirsthead
\multicolumn{2}{l}{Table \thetable\ (continued)} \\
\toprule
Sample & Value \\
\midrule
\endhead
\midrule
\multicolumn{2}{r}{Continued on the next page} \\
\endfoot
\bottomrule
\endlastfoot
1 & 0.82 \\
2 & 0.91 \\
3 & 0.77 \\
\end{longtable}
Result
The compiled example

Open in the editor

Wrap text in a long table

p{...} columns work in a longtable as in a tabular. For X columns that fill the text width, the xltabular package combines longtable and tabularx; its environment takes the total width first.

Complete document:

\documentclass{article}
\usepackage{xltabular}
\usepackage{booktabs}
\begin{document}
\begin{xltabular}{\textwidth}{lX}
\caption{Glossary} \\
\toprule
Term & Meaning \\
\midrule
\endfirsthead
\toprule
Term & Meaning \\
\midrule
\endhead
\bottomrule
\endfoot
Float & An environment that LaTeX moves to a place where it fits, for example the top of the next page. \\
Rule  & A horizontal line in a table. \\
\end{xltabular}
\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages