LaTeX Long Table

Jan. 16, 2025

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\documentclass[a4paper]{article}
\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}
\pagestyle{empty}
\usepackage{longtable}
\usepackage{forloop}

\begin{document}
\newcounter{x}
\begin{longtable}[c]{|c|c|c|}
	\caption{Long table caption.\label{long}}\\
	\hline
	\multicolumn{3}{|c|}{Begin of Table}\\
	\hline
	No. & Something & something else\\
	\hline
	\endfirsthead
	
	\hline
	\multicolumn{3}{|c|}{Continuation of Table \ref{long}}\\
	\hline
	No. & Something & something else\\
	\hline
	\endhead
	
	\hline
	\endfoot
	
	\hline
	\multicolumn{3}{|c|}{End of Table}\\
	\hline\hline
	\endlastfoot
	
	\forloop{x}{0}{\value{x} < 117}{
	  \arabic{x} & Lots of lines & like this\\
	}
	\arabic{x} & Lots of lines & like this\\
\end{longtable}

\end{document}

where1:

There are four longtable-specific elements:

  • \endfirsthead

    Everything above this command will appear at the beginning of the table, in the first page.

  • \endhead

    Whatever you put before this command and below \endfirsthead will be displayed at the top of the table in every page except the first one.

  • \endfoot

    Similar to \endhead, what you put after \endhead and before this command will appear at the bottom of the table in every page except the last one.

  • \endlastfoot

    Similar to \endfirsthead. The elements after \endfoot and before this command will be displayed at the bottom of the table but only in the last page where the table appears.

References