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 \caption and 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 \bottomrule or 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, the xltabular package combines longtable with tabularx's X columns.
  • \footnote works inside a longtable, unlike inside a tabular in 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

In journal templates

Errors you may meet

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

The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained