latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.88k stars 262 forks source link

Longtable continuation header on first page #672

Open paulQdata opened 2 years ago

paulQdata commented 2 years ago

Brief outline of the bug

I have document containg multiples longtables that use the \endfirsthead and \endhead commands to show headers on the first page/second page of the table. Seemingly unrelated changes to the structure of the table (font size) or margins have the effect of showing the continuations headers on the FIRST page of the table. Is there something wrong with the structure of this table?

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{longtable}

  % Any preamble code goes here

\begin{document}
\vspace*{\fill}
Filler
\section{Section}
\subsection{Subsection}
\begin{longtable}[l]{l l l}
F1 & F2 & F3
\endfirsthead
S1 & S2 & S3
\endhead
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\

\end{longtable}
\newpage
%%

  % Demonstration of issue here

\end{document}

Log file (required) and possibly PDF file

example.log example.pdf example.pdf

paulQdata commented 2 years ago

Attaching files... example.log example.pdf

davidcarlisle commented 2 years ago

You didn't mention it but the initial head is being output but at the top of the page, above the section heading

image

I assume you see the same?

I have over the years seen some misplaced headers at the end of the table, but I've never seen this which seems to be a new bug.

So thanks for the test file, I'll need to trace what it is doing (basically the fill glue is confusing longtable, it assumes the section heading will be output on the previous page and things go wrong...

An immediate workaround would be to put \clearpage before the \section so that the page break is handled before longtable starts, but that is not a real solution.

paulQdata commented 2 years ago

Yes. The initial head appears above the section header for me too. I also have a rather more complex example without any \fill glue. I will try and see if I can cut it down to something manageable.

paulQdata commented 2 years ago

This is another example in which the same fault occurs. My tex file consists of a number of sections, each containing one longtable. Preceding each section is the command \needspace{6cm}, needed because there is otherwise an tendency for the section title to end up at the bottom of the page.

\documentclass[a4paper]{article} \usepackage{longtable} \usepackage{needspace} \begin{document} \subsection{A} \begin{longtable}[l]{l} 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ \end{longtable} \needspace{6cm} \subsection{B} \begin{longtable}[l]{l l l } \rule{3cm}{4cm}\ \endfirsthead BS1 & \ \endhead 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \* 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ \end{longtable} \end{document}

needspace_example.pdf

needspace_example.log

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity.

josephwright commented 10 months ago

Another one for v5?

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity.