
Longtable 環境有以下部分:第一個頭和其他 頭。我想加入第三部分最後一個頭它必須位於表格的最後一頁,並且文字略有不同。是否可以?
附言。我不確定這個問題是否需要最少的工作範例。
答案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}