2
\documentclass{article}
\usepackage{longtable}
\begin{document}      
\begin{longtable}{ccc}
\caption{Table 1: my first elaborate caption}\\
\end
\hline
Column 1 & Column 2 & Column 3\\
\hline
\endhead
A & A & A\\
A & A & A\\
\ldots
A & A & A\\

% 1st manual pagebreak: rows before this pagebreak share a common
%                       property A and now they share property B
\pagebreak
% THIS DOES NOT WORK AS EXPECTED:  
\caption{Table 1 continued: following rows share property b (caption updated)}\\
B & B & B\\
B & B & B\\
\ldots
B & B & B\\

% 2nd manual pagebreak: now rows have property C which again should be mentioned in the caption 
\pagebreak
% THIS DOES NOT WORK AS EXPECTED:
\caption{Table 1 continued: following rows share property c}\\
C & C & C\\
C & C & C\\
\end{longtable}
\end{document}

How can I update the caption for later pages within the longtable environment?

I am printing a list of subgroups and insert pagebreaks manually after selected subgroup indices. For example, the first two pages list all subgroups with index 2 to 4. The third and fourth page lists subgroups with index 6 and 8. The fifth page subgroups with index 9. And the remaining pages subgroups with index 12.

Of course, I could define several longtables, but they share the same header row. This means I would have to copy and maintain manually the shared header row.

3
  • What are property A, B, ... ? Where are defined? Your question is unclear.
    – Zarko
    Oct 31 '19 at 11:26
  • They are subgroup indices. They are content related not LaTeX related.
    – Hotschke
    Oct 31 '19 at 11:30
  • are this mean, that in each caption is some explanation of following table body? Why you not simple write this in multicolum cells, which you insert them after each \pgebreak?
    – Zarko
    Oct 31 '19 at 11:33
2

Insert manually pagebreaks, captions & header rows

\documentclass{article}
\usepackage{longtable}

% Define shared header row in a re-usable command:
\newcommand{\myheader}{%
\hline
Subgroup index & Column 2 & Column 3\\
\hline}

\begin{document}      
\begin{longtable}{ccc}
% Page 1
\caption{My first elaborate caption\label{longtable} what subgroups the long table shows beginning with index 2}\\
\myheader
\endfirsthead
2 & A & A\\
2 & A & A\\
\vdots\\
4 & A & A\\
\hline

\pagebreak\\
% Page 2
\multicolumn{3}{c}{\parbox{\LTcapwidth}{\textbf{Table \ref{longtable} Continued:} subgroups with index 6 and 8}}\\
\myheader
6 & B & B\\
6 & B & B\\
\vdots\\
8 & B & B\\
\hline

\pagebreak\\
% Page 3
\multicolumn{3}{c}{\parbox{\LTcapwidth}{\textbf{Table \ref{longtable} Continued:} subgroups with index 9}}\\
\myheader
9 & C & C\\
\vdots\\
9 & C & C\\
\hline

\pagebreak\\
% Page 4
\multicolumn{3}{c}{\parbox{\LTcapwidth}{\textbf{Table \ref{longtable} Continued:} subgroups with index 12}}\\ % still index 9
\myheader
9 & C & C\\
\vdots\\
9 & C & C\\
\hline

% ...
\pagebreak\\
% Page 9
\multicolumn{3}{c}{\parbox{\LTcapwidth}{\textbf{Table \ref{longtable} Continued:} subgroups with index 12}}\\ % still index 12
\myheader
9 & C & C\\
\vdots\\
9 & C & C\\
\hline
\end{longtable}
\end{document}

I assume that the package longtable stores the header row with the \endfirsthead command somewhere. If someone knows how I could refer to this avoiding to have a \newcommand{}, please let me know.

0

Use \endfirsthead and \endhead also for the caption:

\documentclass{article}
\usepackage{longtable}
\begin{document}      
\begin{longtable}{ccc}
\caption{my first elaborate caption}\\\hline
Column 1 & Column 2 & Column 3\\\hline
\endfirsthead

\caption{continued: following rows share property c}\\
Column 1 & Column 2 & Column 3\\\hline
\endhead

A & A & A\\
A & A & A\\
\ldots
A & A & A\\

% 1st manual pagebreak: rows before this pagebreak share a common
%                       property A and now they share property B
\pagebreak
B & B & B\\
B & B & B\\
\ldots
B & B & B\\

\pagebreak
C & C & C\\
C & C & C\\
\end{longtable}
\end{document}
7
  • Thanks for your answer. But this works only if I need two different captions and the first one is only for the first page. But I need the general case N captions each with several pages .
    – Hotschke
    Oct 31 '19 at 10:40
  • 1
    then use a \multicolumn after the manual page break
    – user187802
    Oct 31 '19 at 10:42
  • Yes, that would be a possibility. It means I have to add all pagebreaks and captions manually. In my case this is actually feasible: I have a 9-pages table with five different captions. The subsequent captions are quite short. Repeating them does not bother me.
    – Hotschke
    Oct 31 '19 at 10:49
  • I am struggling with the order of the shared header row and the modified caption: \pagebreak\multicolumn... prints first the shared header row and then the manually inserted caption. Well, I guess this was to be expected. If I also have to add manually the shared header row, it means I have to maintain the shared header row over 9 pages which again leads easily to inconsistencies. In this case I would keep searching for a more automated solution.
    – Hotschke
    Oct 31 '19 at 11:00
  • with \multicolumn you can use only \endfirsthead with \caption
    – user187802
    Oct 31 '19 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.