0

I am troubleshooting a conflict between the Springer Nature sn-jnl document class and the standard \tableofcontents command: If the table of contents (TOC) is entirely contained within a single page (and is not placed on the first page), a complete solution to my problem is given by the accepted answer to a similar question. However, if the TOC spans two pages, this approach only fixes the problem on either the even or odd numbered pages, but NOT both. (And if the TOC spans more than two pages, it doesn't fix the problem at all)

Desired behavior:

The sn-jnl class defines a command \title[optional short title]{article title}. If a "short title" is specified, the document class should produce a left-aligned header on even-numbered pages containing the page number and the specified "short title". If no "short title" is provided, it should behave the same way but print the full "article title" instead of the "short title".

even page header

On odd-numbered pages, it should similarly print a right-aligned header with the page number and the "short title" (or "full title"):

odd page header

Description of problem:

If a TOC is inserted using \tableofcontents, then the title in the header will instead be replaced with "CONTENTS" in both the even and the odd-numbered page headers:

CONTENTS displayed in header

If the TOC spans only a single page, then the desired header behavior can be restored by replacing \tableofcontents with:

\markboth{\leftmark}{\rightmark}
\tableofcontents
\markboth{\leftmark}{\rightmark}

See the accepted answer to a similar question. However, if the TOC spans two pages, then this approach only restores the heading title to either the even pages (if the TOC starts on an even page) or to the odd pages (if the TOC starts on an odd page). Thus, any page whose parity differs from the page on which the TOC begins will still display "CONTENTS" in its header.

MWE:

\documentclass[pdflatex,sn-mathphys]{sn-jnl}
\usepackage{lipsum}
\begin{document}

\title[short title]{Full Title}
\author*[1]{Corresponding Author}
\affil[1]{Institution}
\abstract{\lipsum[4]}
 
\maketitle    
\newpage
    
\markboth{\leftmark}{\rightmark}
\tableofcontents
\markboth{\leftmark}{\rightmark}

\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}

\backmatter
\bmhead{Backmatter}

\begin{appendices}
\section{Appendix}
\end{appendices}

\end{document}
2
  • 1
    \markboth{\leftmark}{\rightmark} looks wrong. \leftmark and \rightmark aren't meant to be used in \markboth. \markboth{short title}{short title} or something similar looks better to me. Commented Nov 13, 2022 at 23:38
  • @PietervanOostrum Good point: It looks to me like sn-jnl stores the short title in variable s@\title. If I replace each instance of markboth{\leftmark}{\rightmark} with \makeatletter \markboth{\s@title}{\s@title} \makeatother, it will now print the "short title" in the headers. It prints it in an upright font rather than italicized but that shouldn't be difficult to change. I don't think I presently understand \markboth well enough to write up an informative answer, so you're welcome to turn your comment into an answer and describe how it works.
    – user143410
    Commented Nov 14, 2022 at 0:07

1 Answer 1

1

\leftmark and \rightmark aren't meant to be used in \markboth. They are for use in headers and footers, and when used anywhere else it should be considered sheer luck if they give the desired result. And here it doesn't.

The sn-jnl documentclass uses \markboth{\textit{\s@title}}{\textit{\s@title}}} where \s@title contains the short title. (These definitions should be used between \makeatletter and \makeatother to accept @ in macro names. It is therefore handy to put this in a macro.) The definition of \tableofcontents is inherited from the article class, so it puts CONTENTS in the header.

So this will work:

Before \begin{document}:

\makeatletter
\newcommand\setshortheader{\markboth{\textit{\s@title}}{\textit{\s@title}}}
\makeatother

In the document text:

\setshortheader
\tableofcontents
\setshortheader

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .