11

I am trying to set up a longtable where the header is repeated on every new page but the caption only appears once at the top of the page.

The table is defined as follows:

\begin{longtable}{|l|l|l|}
\caption{the table caption} \label{tab:11swpkg}\\
\hline
\rowcolor{gray}
HeaderCol1 & HeaderCol2 & HeaderCol3\endhead    
\hline\hline
Item11 & Item12 & Item13 \\
\hline
Item21 & Item22 & Item23 \\
\hline
Item31 & Item32 & Item33 \\
\hline
\end{longtable}

This nearly works because the header is indeed repeated after a page break but so is the caption. How can I get rid of the caption after a page break?

David Carlisle
  • 757,742
Alessandro
  • 243
  • 2
  • 7
  • 3
    Welcome to TeX.SX! Look for \endfirsthead in the manual of longtable – egreg Sep 14 '12 at 15:29
  • 2
    With texdoc longtable you can read the very good documentation of package longtable. On page 4 f you can find what you are searching for. – Mensch Sep 14 '12 at 15:30

2 Answers2

19

This is given as a model for getting you started.

\documentclass{article}
\usepackage{longtable}
\usepackage[table]{xcolor}
\usepackage[textheight=2in]{geometry} %% Just to make textheight smaller

\begin{document}
\begin{longtable}{|l|l|l|}
\caption{the table caption} \label{tab:11swpkg}\\
\hline
%
\rowcolor{gray}
HeaderCol1 & HeaderCol2 & HeaderCol3\\
\hline\hline
\endfirsthead
%
\multicolumn{3}{c}%
        {{\bfseries Table \thetable\ Continued from previous page}} \\
        \hline
\rowcolor{gray}
HeaderCol1 & HeaderCol2 & HeaderCol3\\
\hline\hline
\endhead
%
\multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot
%
\multicolumn{3}{|r|}{{Concluded}} \\ \hline
\endlastfoot
%
Item11 & Item12 & Item13 \\
\hline
Item21 & Item22 & Item23 \\
\hline
Item31 & Item32 & Item33 \\
\hline
Item11 & Item12 & Item13 \\
\hline
Item21 & Item22 & Item23 \\
\hline
Item31 & Item32 & Item33 \\
\hline
Item11 & Item12 & Item13 \\
\hline
Item21 & Item22 & Item23 \\
\hline
Item31 & Item32 & Item33 \\
\hline
\end{longtable}

\end{document}

enter image description here

David Carlisle
  • 757,742
1

You may try the new LaTeX3 package tabularray. It need only one compilation to get the result:

\documentclass{article}
\usepackage[textheight=2in,paperheight=3in]{geometry}

\usepackage{xcolor} \usepackage{tabularray} \UseTblrLibrary{booktabs}

\begin{document}

\DefTblrTemplate{middlehead,lasthead}{default}{Continued from previous page}

\begin{longtblr}[ caption = {The Table Caption}, label = {tab:11swpkg}, ]{colspec={lll},rowhead=1,row{1}={gray9}} \toprule HeaderCol1 & HeaderCol2 & HeaderCol3 \ \midrule Item11 & Item12 & Item13 \ \hline Item21 & Item22 & Item23 \ \hline Item31 & Item32 & Item33 \ \hline Item11 & Item12 & Item13 \ \hline Item21 & Item22 & Item23 \ \hline Item31 & Item32 & Item33 \ \hline Item11 & Item12 & Item13 \ \hline Item21 & Item22 & Item23 \ \hline Item31 & Item32 & Item33 \ \bottomrule \end{longtblr}

\end{document}

enter image description here

L.J.R.
  • 10,932