4

The table header gets generated once and only prints:

Page 1 of 2

... on each and every page. Is there any way update the page number in the longtable header to reflect the actual current page, i.e., in this case:

Page 2 of 2

Speaking of this minimal example:

\documentclass{scrreprt}
\usepackage{longtable}
\usepackage{lastpage}

\begin{document}
\begin{longtable}{| c | c |} \hline
  \textbf{Foo, bar.} & \textbf{Page~\thepage~of~\pageref{LastPage}} \\
  \hline \endhead
  \hline \endfoot
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
\end{longtable}
\end{document}
  • not easily (you may prefer supertabular) longtable headings are only typeset once into a box. However there is an answer here with a patch if you are feeling brave, I'll see if I can find it again.... – David Carlisle Jun 5 '17 at 19:30
  • 1
    this shows a way to alter the longtable foot tex.stackexchange.com/questions/151380/… – David Carlisle Jun 5 '17 at 19:36
  • Does David's link give you a suitable approach? If so, let us know, so that we can close the question as a duplicate of that... – Steven B. Segletes Jun 6 '17 at 11:31
  • No, it's about calculating subtotals in a longtabletable footer. It faces similar issues but I only get a gist of the complexity involved. This hardly answers my question, but thanks for sharing. – Afr Jun 6 '17 at 11:44
1

I really recommend you using the supertabular environment. This will allow you to customize headers and footers (called tails) which way you want.

Here is a simple example based on your post:

\documentclass{scrreprt}
\usepackage{supertabular}
\usepackage{lastpage}

\begin{document}
 \tablehead{\hline\textbf{Foo, bar.} & \textbf{Page~\thepage~of~\pageref{LastPage}}\\\hline }
  \tablefirsthead{\hline\textbf{Foo, bar.} & \textbf{Page~\thepage~of~\pageref{LastPage}}\\\hline}
  \tabletail{\hline}
  \tablelasttail{\hline}
\begin{supertabular}{| c | c |} 
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
\end{supertabular}
\end{document}

A couple of examples:

enter image description here

enter image description here

I provide a new version with booktabs just to typeset the table better (in my opinion), since I removed the vertical and horizontal separators and used the booktabs rules:

\documentclass{scrreprt}
\usepackage{booktabs,supertabular}
\usepackage{lastpage}

\begin{document}
 \tablehead{\toprule\textbf{Foo, bar.} & \textbf{Page~\thepage~of~\pageref{LastPage}}\\\midrule }
  \tablefirsthead{\hline\textbf{Foo, bar.} & \textbf{Page~\thepage~of~\pageref{LastPage}}\\\midrule}
  \tabletail{\bottomrule}
  \tablelasttail{\bottomrule}
\begin{supertabular}{c  c} 
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
  Lorem Ipsum & John Doe \\
\end{supertabular}
\end{document}

And its examples

enter image description here

enter image description here

Note please note that in supertabular jargon:

  • the tablefirsthead of course is the header of the first page for the table,
  • tablehead is the head for the subsequent pages,
  • tabletail is the footer for all the pages, save the last one,
  • tablelasttail is the last footer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.