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}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}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}Pitfalls
longtablewrites the column widths to the.auxfile and reads them in the next run. Compile again while the log says "Table widths have changed. Rerun LaTeX."- Do not put a
longtableinto atableenvironment: a float cannot break across pages. - In a two-column document
longtablestops with the error "longtable not in 1-column mode".
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
longtable - Package
booktabs - Package
tabularx - How-to Table caption and label in LaTeX
- How-to Rotate a table in LaTeX