4

I'm using fancyhdr and everything works well, except one chapter in which I need a longtable in the first page: this causes the header to display the name of the previous chapter. This happens in Overleaf with pdfTex This is pdfTeX, Version 3.141592653-2.6-1.40.28 (TeX Live 2025) (preloaded format=pdflatex 2025.6.16) (but not locally in VSCode with pdfTex This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 23.10.12) (preloaded format=pdflatex 2023.12.16)) Unfortunately I need this to work in Overleaf too, for unrelated reasons, and Overleaf doesn't let me decide the compiler version.

enter image description here

This is a MWE:

\documentclass[twoside]{report} \usepackage{blindtext} \usepackage{longtable} % table on more pages \usepackage{fancyhdr} % fancy headers \usepackage{soul} \usepackage[bf]{titlesec} \linespread{2.0} \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\so{#1}}}{}} % make header uppercase \fancyhf{} %clears all header and footer fields \fancyhead[LE,RO]{\bfseries\rm\thepage} \fancyhead[LO]{\bfseries\footnotesize\rightmark} \fancyhead[RE]{\bfseries\footnotesize\leftmark} % redefine plain style for pagestyle \fancypagestyle{plain}{% \fancyhead{} % get rid of headers \renewcommand{\headrulewidth}{0pt} % and the line } % redefine headings style for pagestyle \fancypagestyle{headings}{% \fancyhead{} % get rid of headers \fancyhead[LE,RO]{\bfseries\rm\thepage} \fancyhead[LO]{\bfseries\rm\rightmark} \fancyhead[RE]{\bfseries\rm\leftmark} } \begin{document} \chapter{Previous Chapter} \blindtext[6] \chapter{This Chapter} Few rows\\ Few rows\\ {\setlength\tabcolsep{8pt} \footnotesize \begin{longtable}{ c | c ||l} \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline \end{longtable}} \normalsize \blindtext[6] \end{document} 
17
  • can you show the start of the .log file from your local compilation? You might be using an older version of texlive. If you are indeed using an older version, you can choose the texlive version in the left hand sidebar of overleaf. Commented Jul 2 at 11:42
  • overleaf or vscode make no difference here, what does matter is the package versions in use, add \listfiles and then show which package versions you have in the version that works, and which in the version that does not work. Commented Jul 2 at 11:43
  • I can reproduce this with an up to date TeX Live 2025. The same issue happens even without fancyhdr, soul and titlesec, if you use \pagestyle{headings}. Then there is still "Chapter 1. PREVIOUS CHAPTER" on page 6 and 8, which are the second and fourth page of Chapter 2. It does not happen with TeX Live 2024. So maybe an issue of the changed mark handling in LaTeX 2025-06-01. Commented Jul 2 at 11:47
  • You can try to select texlive2023 from the overleaf side bar Commented Jul 2 at 11:56
  • 1
    looks like a bug, I opened an issue github.com/latex3/latex2e/issues/1814 Commented Jul 2 at 14:01

1 Answer 1

2

enter image description here

longtable needs to adapt to the new mark code. This will be fixed in a future release see

https://github.com/latex3/latex2e/issues/1814

but until then

enter image description here

\documentclass[twoside]{report} \usepackage{blindtext} \usepackage{longtable} % table on more pages \makeatletter \providecommand\@expl@@@mark@update@singlecol@structures@@{}% for old latex \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@foot \advance\dimen@-\ht\LT@lastfoot \ifdim\dimen@<\ht\z@ \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}% \@makecol \@expl@@@mark@update@singlecol@structures@@ \@outputpage \global\vsize\@colroom \setbox\z@\vbox{\box\LT@head}% \fi \fi \unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi \UseTaggingSocket{tbl/longtable/foot}% \fi \else \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}% \UseTaggingSocket{tbl/longtable/foot}% \@makecol \@expl@@@mark@update@singlecol@structures@@ \@outputpage \global\vsize\@colroom \copy\LT@head\nobreak \fi} \makeatother \usepackage{fancyhdr} % fancy headers \usepackage{soul} \usepackage[bf]{titlesec} \linespread{2.0} \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\so{#1}}}{}} % make header uppercase \fancyhf{} %clears all header and footer fields \fancyhead[LE,RO]{\bfseries\rm\thepage} \fancyhead[LO]{\bfseries\footnotesize\rightmark} \fancyhead[RE]{\bfseries\footnotesize\leftmark} % redefine plain style for pagestyle \fancypagestyle{plain}{% \fancyhead{} % get rid of headers \renewcommand{\headrulewidth}{0pt} % and the line } % redefine headings style for pagestyle \fancypagestyle{headings}{% \fancyhead{} % get rid of headers \fancyhead[LE,RO]{\bfseries\rm\thepage} \fancyhead[LO]{\bfseries\rm\rightmark} \fancyhead[RE]{\bfseries\rm\leftmark} } \begin{document} \chapter{Previous Chapter} \blindtext[6] \chapter{This Chapter} Few rows\\ Few rows\\ {\setlength\tabcolsep{8pt} \footnotesize \begin{longtable}{ c | c ||l} \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline 0 & 1 & A~ \\ 0 & 2 & B~ \\ 0 & 3 & C~ \\ \hline \end{longtable}} \normalsize \blindtext[6] \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.