Sección de última cabecera en un entorno longtabu

Sección de última cabecera en un entorno longtabu

El entorno Longtable tiene secciones paraprimera cabezayotro cabeza. Quiero agregar una tercera sección paraúltima cabezaque debe estar en la última página de una tabla con un texto ligeramente diferente. ¿Es posible?

PD. No estoy seguro de si esta pregunta necesita un ejemplo práctico mínimo.

Respuesta1

(Alguna explicación está escrita en la respuesta deConfigurar título de tabla larga

Es posible. Eche un vistazo al siguiente 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}

Pudimos ver que \ifnum\outputpenalty <-\@Mise utiliza para comprobar si esta página es la última página. Así nos gustaría hacerlo \copy\LT@lastheaden este momento. Sin embargo, en este momento \LT@headya está insertado en la parte superior de \@cclv. (De lo contrario, comprobar la penalización no tiene sentido). Por lo tanto, debemos \setbox\LT@head=\vsplit\@cclv to0pteliminar \LT@headde \@cclv. (Y devuélvelo a \LT@head). Pero esto falla ya que \LT@heada \@cclvcontinuación sigue un \nobreak. Entonces tenemos que modificar la línea \copy\LT@head\nobreakpara obtener el siguiente 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}

información relacionada