A table across several pages in LaTeX (longtable)
Help centre › LaTeX › Tables · Packages: longtable, booktabs
Load \usepackage{longtable} and use \begin{longtable}{…} … \end{longtable} in place of tabular, without a table environment around it; it breaks across pages by itself. Rows above \endfirsthead start the table, rows above \endhead repeat at the top of every following page, and rows above \endfoot and \endlastfoot end each page and the last page.
A complete example
A whole document: paste it into an empty project and compile it.
\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\begin{document}
Table~\ref{tab:samples} lists every sample.
\begin{longtable}{lrr}
\caption{Every sample measured.}\label{tab:samples}\\
\toprule
Sample & Mass (g) & Length (mm) \\
\midrule
\endfirsthead
\caption[]{Every sample measured (continued).}\\
\toprule
Sample & Mass (g) & Length (mm) \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{\emph{Continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
S-001 & 0.37 & 13.5 \\
S-002 & 0.74 & 15.0 \\
S-003 & 1.11 & 16.5 \\
S-004 & 1.48 & 18.0 \\
S-005 & 1.85 & 19.5 \\
S-006 & 2.22 & 21.0 \\
S-007 & 2.59 & 12.0 \\
S-008 & 2.96 & 13.5 \\
S-009 & 3.33 & 15.0 \\
S-010 & 3.70 & 16.5 \\
S-011 & 4.07 & 18.0 \\
S-012 & 4.44 & 19.5 \\
S-013 & 4.81 & 21.0 \\
S-014 & 5.18 & 12.0 \\
S-015 & 5.55 & 13.5 \\
S-016 & 5.92 & 15.0 \\
S-017 & 6.29 & 16.5 \\
S-018 & 6.66 & 18.0 \\
S-019 & 7.03 & 19.5 \\
S-020 & 7.40 & 21.0 \\
S-021 & 7.77 & 12.0 \\
S-022 & 8.14 & 13.5 \\
S-023 & 8.51 & 15.0 \\
S-024 & 8.88 & 16.5 \\
S-025 & 9.25 & 18.0 \\
S-026 & 9.62 & 19.5 \\
S-027 & 9.99 & 21.0 \\
S-028 & 10.36 & 12.0 \\
S-029 & 10.73 & 13.5 \\
S-030 & 11.10 & 15.0 \\
S-031 & 11.47 & 16.5 \\
S-032 & 11.84 & 18.0 \\
S-033 & 12.21 & 19.5 \\
S-034 & 12.58 & 21.0 \\
S-035 & 12.95 & 12.0 \\
S-036 & 13.32 & 13.5 \\
S-037 & 13.69 & 15.0 \\
S-038 & 14.06 & 16.5 \\
S-039 & 14.43 & 18.0 \\
S-040 & 14.80 & 19.5 \\
S-041 & 15.17 & 21.0 \\
S-042 & 15.54 & 12.0 \\
S-043 & 15.91 & 13.5 \\
S-044 & 16.28 & 15.0 \\
S-045 & 16.65 & 16.5 \\
S-046 & 17.02 & 18.0 \\
S-047 & 17.39 & 19.5 \\
S-048 & 17.76 & 21.0 \\
S-049 & 18.13 & 12.0 \\
S-050 & 18.50 & 13.5 \\
S-051 & 18.87 & 15.0 \\
S-052 & 19.24 & 16.5 \\
S-053 & 19.61 & 18.0 \\
S-054 & 19.98 & 19.5 \\
S-055 & 20.35 & 21.0 \\
S-056 & 20.72 & 12.0 \\
S-057 & 21.09 & 13.5 \\
S-058 & 21.46 & 15.0 \\
S-059 & 21.83 & 16.5 \\
S-060 & 22.20 & 18.0 \\
\end{longtable}
\end{document}The parts of a longtable
- Everything before
\endfirsthead: the start of the table on its first page, usually the\captionand the column heads. A caption in a longtable ends with\\. - Before
\endhead: repeated at the top of every later page.\caption[]{… (continued)}repeats the number without adding a second entry to the list of tables. - Before
\endfoot: at the bottom of every page except the last, such as a "continued" note. - Before
\endlastfoot: at the very end, such as the final\bottomruleor notes. - Then the rows. The table breaks only between rows; a row is never split.
Compile twice
longtable works out the column widths across all pages and stores them in the .aux file. Until the second compile, pages can have slightly different widths, and the log says "Table widths have changed. Rerun LaTeX."
Alignment, width and page breaks
- The table is centered by default;
\begin{longtable}[l]{…}sets it at the left margin. \\*ends a row without allowing a page break after it;\newpage(written on its own after\\) forces a break.- For columns that wrap text, use
p{4cm}. For a table of fixed width with stretching columns, thexltabularpackage combines longtable with tabularx'sXcolumns. \footnoteworks inside a longtable, unlike inside atabularin a float.
A long table in landscape
Put the longtable inside the landscape environment of pdflscape: every page of the table is turned. See A landscape table or page.
Common mistakes
- Putting a longtable inside a
tableenvironment: a float cannot break across pages, so the table runs off the bottom. Use longtable on its own. - Forgetting the
\\after\captionin a longtable. - Using
\centeringbefore it: not needed (it is centered already), and it has no effect. - Mixing up
\endfootand\endlastfoot: without\endlastfoot, the last page also gets the "continued" note. - Expecting
tabularx'sXcolumns in a longtable: usexltabularinstead.
In journal templates
- longtable does not work in two-column mode; it stops with "longtable not in 1-column mode". In a two-column class, split the table into several
table*floats of one page each ("Table 2 (continued)"), or move the full table to supplementary material, as many journals prefer.
Errors you may meet
- LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
- Extra alignment tab has been changed to \cr.A table or matrix row has more & cells than the column specification allows. Add a column to {…}, remove an &, or add a missing \\.
- Misplaced alignment tab character &.An & appeared outside a table or align environment. In text write \&; in a bibliography fix the & in the .bib entry; in maths use align.
In Manulyx
Insert → Table puts a table environment in place, and pasting a range copied from a spreadsheet (two or more rows and columns) goes in as a LaTeX table, with booktabs rules when the paper loads booktabs and \hline otherwise; a notice offers the plain text back.
Write in Manulyx for free · Journal templates
Related
- A landscape table or page in LaTeXTurn a wide table sideways: pdflscape's landscape environment rotates whole pages (upright on screen); rotating's sidewaystable rotates a float.
- Professional-looking tables in LaTeX with booktabsMake LaTeX tables look typeset: booktabs rules (\toprule, \midrule, \bottomrule, \cmidrule), no vertical lines, and aligned numbers.
- Make a LaTeX table fit the page widthFit a too-wide LaTeX table: tabularx X columns, p{} columns that wrap, a smaller font, less column spacing, and why \resizebox is a last resort.
- Table notes and footnotes in a LaTeX table (threeparttable)Add notes under a LaTeX table with markers in the cells, using threeparttable's \tnote and tablenotes, and why \footnote inside a table goes missing.
- Merge cells in a LaTeX table: multirow and multicolumnMerge table cells across columns with \multicolumn and across rows with \multirow (multirow package), with booktabs rules and \cline/\cmidrule.
The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained