我想問一下關於longtable
包裹的問題。我已經在其他論壇發布了。
我有一個使用包的長表格(幾頁長的表格)longtable
,我想在每張表格的底部添加一個表格標題,但在第一頁中添加一個不同的標題。
longtable
軟體包允許在表格的第一頁 ( \endfirsthead
) 中使用不同的「頁首」和/或在表格的最後一頁 ( \endlastfoot
) 中使用不同的「頁尾」。我想做的是在表格的第一頁中使用不同的腳標題。
我的例子是這樣的:
第一頁表腳標題:「表 1.2:表說明等等,等等......」。
以下頁表腳標題為:「表 1.2(續):表說明等等…」。
它類似於longtable
包文檔中有關 的用法的範例\endfirsthead
,但我想將其放在表格的底部,因為我的文檔中所有圖形和表格的標題都位於底部,而不是頂部。
我想做的事有那麼奇怪嗎?我怎樣才能做到這一點longtable
?
如果您能給我任何提示或技巧,我將非常感激。
預先感謝您的回答! :)
答案1
您可以嘗試以下範例。這增加了\endfirstfoot
.
\documentclass{article}
\usepackage[a6paper,showframe]{geometry}
\usepackage{longtable}
\makeatletter
\newbox\LT@firstfoot
\def\endfirstfoot{\LT@end@hd@ft\LT@firstfoot}
\newdimen\LT@footdiff
\def\LT@start{%
\let\LT@start\endgraf
\endgraf\penalty\z@
\vskip\LTpre\endgraf
\LT@footdiff-\ht\LT@foot
\advance\LT@footdiff\ht\LT@firstfoot
\dimen@\pagetotal
\advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \ht\ifvoid\LT@firstfoot\LT@foot\else\LT@firstfoot\fi
\dimen@ii\vfuzz
\vfuzz\maxdimen
\setbox\tw@\copy\z@
\setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
\setbox\tw@\vbox{\unvbox\tw@}%
\vfuzz\dimen@ii
\advance\dimen@ \ht
\ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@\dp
\ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@ -\pagegoal
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LT@firstfoot
\ifvoid\LT@foot
\else
\advance\vsize-\ht\LT@foot
\global\advance\@colroom-\ht\LT@foot
\dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
\maxdepth\z@
\fi
\else
\advance\vsize-\ht\LT@firstfoot
\global\advance\@colroom-\ht\LT@firstfoot
\dimen@\pagegoal\advance\dimen@-\ht\LT@firstfoot\pagegoal\dimen@
\maxdepth\z@
\fi
\ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
\output{\LT@output}%
}
\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
\ifvoid\LT@firstfoot
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
\@makecol
\@outputpage
\global\vsize\@colroom
\else
\setbox\@cclv\vbox{\unvbox\@cclv\box\LT@firstfoot\vss}%
\@makecol
\@outputpage
\global\advance\@colroom\LT@footdiff
\global\vsize\@colroom
\fi
\copy\LT@head\nobreak
\fi
}
\makeatother
\begin{document}
\begin{longtable}{l}
\hline first head\\\hline\endfirsthead
\hline head\\\hline\endhead
\hline first foot\\\hline\endfirstfoot
\hline (continued)\\foot\\\hline\endfoot
\hline last foot\\\hline\endlastfoot
A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z\\
a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z\\
0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\
\end{longtable}
\end{document}
Skillmon 的附錄:
上面的方法將使用普通的foot
而不是firstfoot
如果longtable
只需要一個頁面並且lastfoot
沒有被使用。以下程式碼與上面的程式碼幾乎相同,但它將firstfoot
在單一頁面上使用longtable
.
單頁頁腳的優先順序longtable
為:
lastfoot
,如果它是空的firstfoot
,如果它是空的foot
。
代碼:
\documentclass{article}
\usepackage[a6paper,showframe]{geometry}
\usepackage{longtable}
\makeatletter
\newbox\LT@firstfoot
\def\endfirstfoot{\LT@end@hd@ft\LT@firstfoot}
\newdimen\LT@footdiff
\def\LT@start{%
\let\LT@start\endgraf
\endgraf\penalty\z@
\vskip\LTpre\endgraf
\LT@footdiff-\ht\LT@foot
\advance\LT@footdiff\ht\LT@firstfoot
\dimen@\pagetotal
\advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \ht\ifvoid\LT@firstfoot\LT@foot\else\LT@firstfoot\fi
\dimen@ii\vfuzz
\vfuzz\maxdimen
\setbox\tw@\copy\z@
\setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
\setbox\tw@\vbox{\unvbox\tw@}%
\vfuzz\dimen@ii
\advance\dimen@ \ht
\ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@\dp
\ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@ -\pagegoal
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LT@firstfoot
\ifvoid\LT@foot
\else
\advance\vsize-\ht\LT@foot
\global\advance\@colroom-\ht\LT@foot
\dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
\maxdepth\z@
\fi
\else
\advance\vsize-\ht\LT@firstfoot
\global\advance\@colroom-\ht\LT@firstfoot
\dimen@\pagegoal\advance\dimen@-\ht\LT@firstfoot\pagegoal\dimen@
\maxdepth\z@
\fi
\ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
\output{\LT@output}%
}
\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
\ifvoid\LT@firstfoot
\LT@foot
\else
\LT@firstfoot
\fi
\else
\LT@lastfoot
\fi
}%
\fi
\else
\ifvoid\LT@firstfoot
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
\@makecol
\@outputpage
\global\vsize\@colroom
\else
\setbox\@cclv\vbox{\unvbox\@cclv\box\LT@firstfoot\vss}%
\@makecol
\@outputpage
\global\advance\@colroom\LT@footdiff
\global\vsize\@colroom
\fi
\copy\LT@head\nobreak
\fi
}
\makeatother
\begin{document}
\begin{longtable}{l}
\hline first head\\\hline\endfirsthead
\hline head\\\hline\endhead
\hline first foot\\\hline\endfirstfoot
\hline (continued)\\foot\\\hline\endfoot
\hline last foot\\\hline\endlastfoot
A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z\\
a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z\\
0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\
\end{longtable}
\end{document}
答案2
新的 LaTeX3 包tabularray
最近(在版本 2021L 中)使用以下範本新增了長表的支援:firsthead
、firstfoot
、middlehead
、middlefoot
和lasthead
。lastfoot
\documentclass[12pt]{article}
\usepackage[a6paper,margin=15mm]{geometry}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks}
\begin{document}
\DefTblrTemplate{head}{default}{}
\DefTblrTemplate{firstfoot}{default}{
\UseTblrTemplate{caption}{default}
}
\DefTblrTemplate{middlefoot,lastfoot}{default}{
\UseTblrTemplate{capcont}{default}
}
\SetTblrStyle{firstfoot}{blue3}
\SetTblrStyle{middlefoot}{\itshape}
\SetTblrStyle{caption-tag}{red3}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
\begin{longtblr}[
caption = {Long Long Long Long Long Long Tabular},
entry = {Short Caption},
label = {tblr:test},
]{
colspec = {XXX}, width = \linewidth,
rowhead = 2, rowfoot = 1
}
\hline
\SetRow{purple7} Head & Head & Head \\
\hline
\SetRow{purple7} Head & Head & Head \\
\hline
Alpha & Beta & Gamma \\
\hline
Epsilon & Zeta & Eta \\
\hline
Iota & Kappa & Lambda \\
\hline
Nu & Xi & Omicron \\
\hline
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
\hline
Alpha & Beta & Gamma \\
\hline
Epsilon & Zeta & Eta \\
\hline
Iota & Kappa & Lambda \\
\hline
Nu & Xi & Omicron \\
\hline
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
\hline
Alpha & Beta & Gamma \\
\hline
Epsilon & Zeta & Eta \\
\hline
Iota & Kappa & Lambda \\
\hline
Nu & Xi & Omicron \\
\hline
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
\hline
Alpha & Beta & Gamma \\
\hline
Epsilon & Zeta & Eta \\
\hline
Iota & Kappa & Lambda \\
\hline
Nu & Xi & Omicron \\
\hline
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
\hline
Alpha & Beta & Gamma \\
\hline
Epsilon & Zeta & Eta \\
\hline
Iota & Kappa & Lambda \\
\hline
Nu & Xi & Omicron \\
\hline
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
\hline
\SetRow{blue7} Foot & Foot & Foot \\
\hline
\end{longtblr}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
\end{document}