2

I am trying to use fancyhdr to create headings on some notes I am writing (article class, one sided). I would like to have the section name and number on the left and the subsection name and number on the right. My issue is that the subsection header does not appear on certain pages. Here is my code:

\usepackage[utf8]{inputenc}
\usepackage{amsthm, amsmath, amssymb, amsfonts, enumitem, mathtools, etoolbox, mathrsfs, fancyhdr}
\usepackage[margin=1in]{geometry}

\pagestyle{fancy} 
\fancyhead{} 
\fancyfoot{}
\fancyfoot[C]{\thepage}
\fancyhead[L]{\nouppercase{\leftmark}}
\fancyhead[R]{\rightmark} 
\headheight 15pt

And here is the output. The first two images show how I would like every page to look: enter image description here

enter image description here

These two show the problem I am having:

enter image description here enter image description here

As you can see, in the last two images the subsection does not appear in the header even though a new subsection starts on those pages. Is there a way around this?

EDIT: Here is a working example of the issue:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm, amsmath, amssymb, amsfonts, enumitem, mathtools, etoolbox, mathrsfs, fancyhdr, extramarks}
\usepackage[margin=1in]{geometry}
\usepackage{blindtext}

\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyfoot[C]{\thepage}
\fancyhead[L]{\nouppercase{\firstleftmark}}
\fancyhead[R]{\firstrightmark} 
\headheight 15pt

\renewcommand{\subsectionmark}[1]{\markright{\thesubsection.\ #1}}

\title{test}
\date{September 2019}

\begin{document}
\section{Intro}
\subsection{Subsection 1}

\blindtext[3]
\pagebreak

\subsection{Subsection 2}

\blindtext[3]
\pagebreak

\section{Another section}
\subsection{Sub 3}
\blindtext[1]

\subsection{Sub 4}
\blindtext[1]
\end{document}

When compiled the first and third pages are missing the subsection header. It seems this only occurs when a new section is started first thing on the page.

  • 2
    Welcome to TeX.SX! Please add a small but complete, compilable document to your question that can be used to reproduce the problem. – siracusa Sep 30 at 3:09
  • 4
    \rightmark shows the first right mark on the page, and the right mark on the problematic pages is filled by the \section command and so it is empty. You could try the extramarks package and use \lastrightmark instead. – Ulrike Fischer Sep 30 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.