0

I have starred sections at the end of a chapter that do not show up in the headers. The MWE is:

\documentclass{memoir}
\usepackage{lipsum}
\begin{document}
\chapter{Some chapter}
\section*{Some section} % empty header if starred
\lipsum[1-9]
\end{document}

The header is empty:

enter image description here

The remedy suggested in this answer does not work for sections. How can I get the title of starred sections into the header?

user1362373
  • 2,859
  • 1
    Counter question: are there also numbered sections? If not then just disable numbering and use section. Otherwise use markright/-both manually – daleif Dec 31 '23 at 20:36
  • Yes, my actual document also contains numbered sections. I removed those for the purpose of the MWE. – user1362373 Dec 31 '23 at 20:50
  • @daleif: Thanks, what you proposed seems to be the simplest solution, although it requires that I set it manually in each chapter. It's not a major problem in that I can isolate the needed code in a file that I input at the required places. Do you want to add an answer that I could accept? – user1362373 Jan 01 '24 at 10:35

1 Answers1

1

Not sure why you would do it.

Remove the toc related parts if you want that the section goes in the table of contents.

\documentclass{memoir}
\usepackage{lipsum}

\AtBeginDocument{% \edef\defaultsecnumdepth{\the\value{secnumdepth}}% \edef\defaulttocdepth{\the\value{tocdepth}}% }

\newcommand{\specialsection}[1]{% \setcounter{secnumdepth}{0}% \addtocontents{toc}{\setcounter{tocdepth}{0}}% \section{#1}% \setcounter{secnumdepth}{\defaultsecnumdepth}% \addtocontents{toc}{\setcounter{tocdepth}{\defaulttocdepth}}% }

\begin{document}

\tableofcontents*

\chapter{Some chapter}

\specialsection{Some section}

\lipsum[1-20]

\section{test}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks. Regarding your comment "Not sure why you would do it": It's not uncommon to have unnumbered sections at the ends of chapters for references and exercises. (Cambridge University Press is one example.) It seems logical to me that you would show the titles of these sections in the headers irrespective of whether they are numbered or not. – user1362373 Jan 01 '24 at 10:33
  • @user1362373 With \markright you're completely responsible about the appearance of the header, because none of the instructions issued by \sectionmark would apply. But \sectionmark usually adds the section number… – egreg Jan 01 '24 at 10:35