0

My question is essentially a follow-up to Sectionmark command ignored in running head of first section page. The solution was to replace, in the definition of \sectionmark, a higher-level command \markright with a lower-level command \rightmark. It worked like a charm for the MWE of that question. However, it does not work for me, as in my book some chapters start with a long preamble before any section commands appear. The result is that the running head prints the number and heading of the last section of previous chapter (whereas with a standard definition of \sectionmark, no headers appear on those sectionless pages). Note that issuing \sectionmark after \chapter command does not solve the problem as the running head still contains wrong section number. Here is an MWE adopted from the above question:

\documentclass[10pt]{book}
\usepackage{kantlipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}} \renewcommand{\sectionmark}[1]{\gdef\rightmark{\thesection.\ #1}} % \fancyhead[LO]{\rightmark} \fancyhead[RE]{\leftmark} \fancyhead[RO]{\thepage} \fancyhead[LE]{\thepage} \renewcommand{\headrulewidth}{0pt}

\begin{document}

\chapter{One} \section{First section of chapter one} \kant[1-3] \section{Second section of chapter one} \kant[8-15]

\chapter{Two} \kant[1-10] \section{First section of chapter two: Too much text for a running head} \sectionmark{First section of chapter two} \kant[11-15] \end{document}

Furthermore, running heads in the biblatex bibliography are also distorted by this definition of \sectionmark, but these are harder to reproduce in MWE. Thanks a lot in advance for your help.

Here is a further MWE demonstrating the problem that if the \section command falls on an odd page, the running head on that page shows the full heading rather than the shortened one given in \sectionmark.

\documentclass[10pt]{book}
\usepackage{kantlipsum}
\usepackage{fancyhdr,etoolbox}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1] {\markboth{\chaptername\ \thechapter.\ #1}{\chaptername\ \thechapter.\ #1}} \fancyhead[LO]{\rightmark} \fancyhead[RE]{\leftmark} \fancyhead[RO]{\thepage} \fancyhead[LE]{\thepage} \renewcommand{\headrulewidth}{0pt}

\begin{document}

\chapter{One} \section{First section of chapter one} \kant[1-3] \section{Second section of chapter one} \kant[8-15]

\chapter{Two} \kant[1-15] \section{First section of chapter two: Too much text for a running head} \sectionmark{First section of chapter two} \kant[11-15] \end{document}

Boris
  • 1
  • If there has not been a \section then what would you want the running head to show? Perhaps "No section yet specified"? --- GOM – Peter Wilson Nov 06 '22 at 18:50
  • Making the rash assumption that if the first section in a chapter doesn't come early enough, and the offending running head is on a right-hand page, you can simply, just after the \chapter input, \markright{<chapter title>}. – barbara beeton Nov 06 '22 at 18:58
  • @PeterWilson, I would be happy with an empty running head (as was the case when using the default definition of \sectionmark). Or, as @barbarabeeton suggested, the chapter title... Thank you! – Boris Nov 07 '22 at 01:06
  • @barbarabeeton, I have tried and, unfortunately, it changes nothing. – Boris Nov 07 '22 at 01:10

1 Answers1

1

The cited answer looks quite wrong. \rightmark is not a low-level counterpart to \markright: The first command retrieves a value while the second stores it. LaTeX stores the values for good reasons with \mark commands and not with a simple \def and the answer destroy this.

You seem to want some text if there is no section, so I would suggest that you store something into the right mark with chapter too:

\documentclass[10pt]{book}
\usepackage{kantlipsum}
\usepackage{fancyhdr,etoolbox}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1] {\markboth{\chaptername\ \thechapter.\ #1}{\chaptername\ \thechapter.\ #1}} \fancyhead[LO]{\rightmark} \fancyhead[RE]{\leftmark} \fancyhead[RO]{\thepage} \fancyhead[LE]{\thepage} \renewcommand{\headrulewidth}{0pt}

\begin{document}

\chapter{One} \section{First section of chapter one} \kant[1-3] \section{Second section of chapter one} \kant[8-15]

\chapter{Two} \kant[1-10] \section{First section of chapter two: Too much text for a running head} \sectionmark{First section of chapter two} \kant[11-15] \end{document}

Ulrike Fischer
  • 327,261
  • thank you. However, my core problem is that when \section' command falls on an odd page, the running head on that page shows argument of\section' instead of argument of `\sectionmark' . Thus i tried to use the solution provided in link. If that answer is incorrect, can you please suggest a correct one? I will append an MWE to my question. – Boris Nov 07 '22 at 13:13
  • 1
    see https://texfaq.org/FAQ-runheadtoobig (probably). – Ulrike Fischer Nov 07 '22 at 13:17
  • this is embarrassingly simple. It works, including for my 500-pages book. Thank you! – Boris Nov 07 '22 at 13:43