Skillmon 的附录:

Skillmon 的附录:

我想问一个关于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而不是。以下代码与上述代码几乎相同,但它将在单个页面上使用。firstfootlongtablelastfootfirstfootlongtable

单页页脚的优先级longtable为:

  1. lastfoot,如果为空

  2. firstfoot,如果为空

  3. 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、、、、和。firstfootmiddleheadmiddlefootlastheadlastfoot

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

在此处输入图片描述

相关内容