4

The default behavior of the memoir package is to change the headings immediately upon sectioning. This is counterintuitive to me, as I think the headings are to remind the reader of the section they are currently reading. This is not necessary when a new section begins, as the section header does that for them. The reader still needs a reminder as to which section they are finishing rather than which they are starting.

How can I change that behavior so the headers are updated on the next page after a section command, rather than the actual page of the section command?

If you run the MWE I provide below, look at pages 2–4. I want the following headers:

  • page 2: the heading is as I want it
  • page 3: I want the heading to match that of page 2
  • page 4: the heading is as I want it

    Can I do this within memoir?

MWE:

\documentclass[17pt,letterpaper,oneside]{memoir}
\usepackage{lipsum}

\copypagestyle{MWE}{headings}
\makepsmarks{MWE}{%
    \nouppercaseheads
    \createmark{section}{right}{nonumber}{}{}
    \createmark{chapter}{left}{shownumber}{Chapter\ }{:\ }}
\makeoddhead{MWE}{\leftmark}{}{\rightmark}
\makeoddfoot{MWE}{}{\thepage}{}
\pagestyle{MWE}


\begin{document}
\chapter{The MWE}
    \section{Introduction}
        \lipsum[1-5]
    \section{History of the MWE}
        \lipsum[6-10]

\end{document}
4
+50

For each mark there are three variables set by TeX: \botmark, \firstmark and \topmark.

While \leftmark uses \botmark (the last set mark on the current page) \rightmark uses \firstmark (the first set mark on the current page).

But you want to use the \topmark which is the last mark of the previous page.

Based on the definition of \rightmark in latex.ltx

\let\@rightmark\@secondoftwo
...
\def\rightmark{\expandafter\@rightmark\firstmark\@empty\@empty}

you can define

\providecommand*{\righttopmark}{\expandafter\@rightmark\topmark\@empty\@empty}

and then use \righttopmark instead of \rightmark:

\documentclass[17pt,letterpaper,oneside]{memoir}
\usepackage{lipsum}
\makeatletter
\providecommand*{\righttopmark}{\expandafter\@rightmark\topmark\@empty\@empty}
\makeatother
\copypagestyle{MWE}{headings}
\makepsmarks{MWE}{%
  \nouppercaseheads
  \createmark{section}{right}{nonumber}{}{}
  \createmark{chapter}{left}{shownumber}{Chapter\ }{:\ }}
\makeoddhead{MWE}{\leftmark}{}{\righttopmark}
\makeoddfoot{MWE}{}{\thepage}{}
\pagestyle{MWE}


\begin{document}
\chapter{The MWE}
  \section{Introduction}
    \lipsum[1-5]
  \section{History of the MWE}
    \lipsum[6-10]
\end{document}

enter image description here enter image description here

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.