Longtable 环境有以下部分:第一个头和其他 头。我想添加第三部分最后一颗头必须位于表格的最后一页,且文本略有不同。这可能吗?
PS. 我不确定这个问题是否需要最少的工作示例。
答案1
(答案中写了一些解释配置长表格标题
这是有可能的。看看下面的代码longtable.sty
\def\LT@output{% \ifnum\outputpenalty <-\@Mi%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifnum\outputpenalty > -\LT@end@pen \LT@err{floats and marginpars not allowed in a longtable}\@ehc \else \setbox\z@\vbox{\unvbox\@cclv}% \ifdim \ht\LT@lastfoot>\ht\LT@foot \dimen@\pagegoal \advance\dimen@-\ht\LT@lastfoot \ifdim\dimen@<\ht\z@ \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}% \@makecol \@outputpage \setbox\z@\vbox{\box\LT@head}% \fi \fi \global\@colroom\@colht \global\vsize\@colht \vbox {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}% \fi \else \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}% \@makecol \@outputpage \global\vsize\@colroom \copy\LT@head\nobreak%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi}
我们可以看到,\ifnum\outputpenalty <-\@Mi
用于检查此页面是否是最后一页。因此,我们希望\copy\LT@lasthead
此时。但是,此时\LT@head
已经插入到的顶部\@cclv
。(否则检查惩罚就没有意义了。)因此,我们需要从中\setbox\LT@head=\vsplit\@cclv to0pt
删除。(并将其返回到)。但这会失败,因为在后面跟着一个。因此,我们必须修改该行以获得以下代码:\LT@head
\@cclv
\LT@head
\LT@head
\@cclv
\nobreak
\copy\LT@head\nobreak
\documentclass{article}
\usepackage{longtable,setspace}
\begin{document}
\listoftables
\setstretch{5}
\makeatletter
\newif\ifmorethanonepage\morethanonepagefalse
\newbox\LT@lasthead\def\endlasthead{\LT@end@hd@ft\LT@lasthead}
\def\LT@output{%
\ifnum\outputpenalty <-\@Mi
\ifmorethanonepage\copy\LT@lasthead\fi%%%%%
\setbox\LT@head=\vsplit\@cclv to0pt%%%%%%
\ifnum\outputpenalty > -\LT@end@pen
\LT@err{floats and marginpars not allowed in a longtable}\@ehc
\else
\setbox\z@\vbox{\unvbox\@cclv}%
\ifdim \ht\LT@lastfoot>\ht\LT@foot
\dimen@\pagegoal
\advance\dimen@-\ht\LT@lastfoot
\ifdim\dimen@<\ht\z@
\setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
\@makecol
\@outputpage
\setbox\z@\vbox{\box\LT@lasthead}%
\fi
\fi
\global\@colroom\@colht
\global\vsize\@colht
\vbox
{\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
\fi
\else
\global\morethanonepagetrue%
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
\@makecol
\@outputpage
\global\vsize\@colroom
\copy\LT@head%%%%%\nobreak
\fi}
\makeatother
\begin{longtable}{ccc}
\caption{FIRST} \\\endfirsthead
\caption{OTHER} \\\endhead
\caption{LAST} \\\endlasthead
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 \\ \end{longtable}
\end{document}