长表:手动分页后更新标题

长表:手动分页后更新标题
\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}

如何在 longtable 环境中更新后续页面的标题?

我正在打印子组列表,并在选定的子组索引后手动插入分页符。例如,前两页列出了索引为 2 至 4 的所有子组。第三页和第四页列出了索引为 6 和 8 的子组。第五页列出了索引为 9 的子组。其余页面列出了索引为 12 的子组。

当然,我可以定义多个 longtable,但它们共享同一个标题行。这意味着我必须手动复制和维护共享的标题行。

答案1

手动插入分页符、标题和标题行

\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}

我假设包将longtable带有命令的标题行存储\endfirsthead在某个地方。如果有人知道我该如何引用它以避免出现\newcommand{},请告诉我。

答案2

使用\endfirsthead\endhead作为标题:

\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}

相关内容