0

How can I change the default behaviour of \rightmark to display the last defined section before the current page. The default behaviour appears to be the last defined section before the current page IF there are no new sections on the current page.

For example, the following produces a sample document with the default behaviour of \rightmark.

\documentclass[a4paper,oneside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\rightmark}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\begin{document}
\chapter{Lorem Ipsum :)}
\section{Paragraphs 1 - 5}
\lipsum[1-5]
\section{Paragraphs 6 - 10}
\lipsum[1-5]
\section{Paragraphs 11 - 15}
\lipsum[1-5]
\end{document}

It looks a bit like this

enter image description here

I would like to make it look a bit more like this. Notice the header now references the last defined section

enter image description here

  • latex uses \firstmark and \botmark but you want \topmark – David Carlisle Sep 1 '18 at 15:58
  • @DavidCarlisle Thank you for the comment. I managed to get it working with that information. Would you agree with the approach I took in the answer to achieve the result or is there a better way? – Dan Sep 1 '18 at 17:23
  • @DavidCarlisle Thanks again for the advice, but do you know why \topmark might be prefixed by CONTENTS? I posted a new question about it here. I appreciate any help you can give – Dan Sep 1 '18 at 19:57
0

Credits to David Carlisle for pointing me to \topmark


As mentioned before, this can be achieved by using \topmark. However, \topmark returns the chapter as part of the value. So this can be got around by "silencing" the \chaptermark.

In my case, I used

%Header / Footer info
\pagestyle{fancy}

%Change commands so when `topmark` is used, the last defined section before the current page is used
\renewcommand{\chaptermark}[1]{\markright{#1}}
%\renewcommand{\sectionmark}[1]{\markright{#1}} %Uncomment this line if you don't like numbers

%Define the header / footer
\fancyhf{}
\fancyhead[L]{\topmark}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

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.