Seção Lasthead em um ambiente longtabu

Seção Lasthead em um ambiente longtabu

O ambiente Longtable possui seções paraprimeira cabeçaeoutro cabeça. Quero adicionar a terceira seção paraúltima cabeçaque deve estar na última página de uma tabela com texto ligeiramente diferente. É possível?

PS. Não tenho certeza se esta questão precisa de um exemplo mínimo de trabalho.

Responder1

(Alguma explicação está escrita na resposta deConfigurar legenda de tabela longa

É possível. Dê uma olhada no seguinte código delongtable.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}

Pudemos ver que \ifnum\outputpenalty <-\@Mié usado para verificar se esta página é a última página. Então, gostaríamos de fazer isso \copy\LT@lastheadneste momento. Porém, neste momento \LT@headjá está inserido no topo do \@cclv. (Caso contrário, verificar a penalidade não faz sentido.) Portanto, precisamos \setbox\LT@head=\vsplit\@cclv to0ptremover \LT@headfrom \@cclv. (E devolva-o para \LT@head). Mas isso falha, pois \LT@headsegue \@cclva \nobreak. Portanto, temos que modificar a linha \copy\LT@head\nobreakpara obter o seguinte código:

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

informação relacionada