The longtable package
Provides the longtable environment for tables that continue over several pages, with a head and foot that repeat on every page.
Loading the package
\usepackage{longtable}A tabular is one box that cannot be split; one that is longer than the page runs off its lower edge. longtable has the same column argument and the same row syntax, but LaTeX may break the page between any two rows.
longtable replaces both table and tabular. It is not a float, so it starts where it stands in the source, and \caption and \label are written inside it as the first row. Four commands mark special rows: everything before \endfirsthead is the head on the first page, before \endhead the head on the following pages, before \endfoot the foot at each page break, and before \endlastfoot the foot at the end of the table.
Main commands
\begin{longtable}{lrr} ... \end{longtable} | Table that may break across pages. |
\caption{...}\label{tab:x} \\ | Caption as a table row; the \\ after it is required. |
\endfirsthead | Ends the head of the first page. |
\endhead | Ends the head that is repeated on every following page. |
\endfoot | Ends the foot that is printed before every page break, for example "continued on the next page". |
\endlastfoot | Ends the foot of the last page. |
\caption[]{... (continued)} \\ | Caption for the repeated head; the empty brackets keep it out of the list of tables. |
Complete example
\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\begin{document}
\begin{longtable}{lrr}
\caption{Monthly measurements}\label{tab:months} \\
\toprule
Month & Rain (mm) & Sun (h) \\
\midrule
\endfirsthead
\toprule
Month & Rain (mm) & Sun (h) \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{continued on the next page} \\
\endfoot
\bottomrule
\endlastfoot
January & 62 & 48 \\
February & 45 & 75 \\
March & 51 & 120 \\
\end{longtable}
\end{document}Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.
Pitfalls
- The column widths are stored in the
.auxfile and can differ from page to page in the first run. The log then says "Table widths have changed. Rerun LaTeX."; compile again. - Do not put a
longtableinto atableenvironment. A float cannot break, so the table runs off the page and the log shows Float too large for page by 99.90506pt. \captionwithout\\after it gives Extra alignment tab has been changed to \cr.- In a
twocolumndocument the environment stops with "longtable not in 1-column mode". - The column type
Xoftabularxis not available. The packagexltabularprovides an environment with both.
Related pages
- How-to Table across multiple pages in LaTeX
- How-to Table caption and label in LaTeX
- Package
booktabs - Package
tabularx - Package
pdflscape - How-to Footnotes in a table in LaTeX