1

Context

I am trying to display the name of a numberless section (\section*{}) in the header of a document with the fancyhdr package.

I am already displaying the name of sections and removing their numbering from the label with the extramark and titlesec packages.

Issue

The numberless section does not appear in the header leaving it empty. It seems to work properly for the table of contents which is also a numberless section (correct me if I am wrong).

MWE

\documentclass{article}

\usepackage{mwe}

\usepackage{extramarks}
\usepackage{fancyhdr}
\usepackage{titlesec}

\title{Document}

\fancyhead[L]{}
\fancyhead[R]{
  {\nouppercase
  \firstleftmark}
}

\pagestyle{fancy}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}}

\begin{document}

\section*{Test}
\newpage
\tableofcontents
\newpage
\blinddocument

\end{document}

Example

Numberless section empty header Contents displaying properly Classic section

3

You can manually trigger the entry in the headline for the unnumbered section:

\documentclass{article}

\usepackage{mwe}

\usepackage{extramarks}
\usepackage{fancyhdr}
\usepackage{titlesec}

\title{Document}

\fancyhead[L]{}
\fancyhead[R]{
  {\nouppercase
  \firstleftmark}
}

\pagestyle{fancy}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}}

\begin{document}

\section*{Test}
\markboth{Test}{}

\newpage
\tableofcontents
\newpage
\blinddocument

\end{document}
|improve this answer|||||
  • While this does indeed fix this specific issue, it does require to type twice the name of the section. Is it possible to automatically retrieve it somehow? – Akaizoku May 24 '18 at 10:46
  • 2
    @Florian Something like \renewcommand*{\secwhead}[1]{\section*{#1}\sectionmark{#1}}? (Could be improved for optional arguments etc. etc.) – moewe May 24 '18 at 11:13

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.