# Section Name and Number not matching in fancyhdr

I would like to use fancyhdr to have even page headers like this (page number on left, part name on right): and odd page headers like this (section number $\blacklozenge$ section name on the left and page number on the right.): My code looks like this:

\pagenumbering{arabic}
\setcounter{page}{1}
\pagestyle{fancy}
\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhead[LO]{\fancyplain{}{\thesection\ $\blacklozenge$ \textsl{\textsc{\rightmark}}}}
\fancyfoot[C]{}


The problem that I am having is that occasionally, the section number on the odd page heading does not match the section name next to it. As you can see, this is section 2.3 content on the page and the section name is that of 2.3 but the section number has increased to 2.4 when really it should not, in my opinion have increased until page 65 (and even if it was to increase here, the section name in the header should reflect this too.).

My minimal example is:

\documentclass[11pt, letterpaper,twoside,openright]{report}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage[margin=1.54in]{geometry}
\usepackage{amssymb}
\usepackage{lipsum}

\pagenumbering{arabic}
\setcounter{page}{1}
\pagestyle{fancy}
\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhead[LO]{\fancyplain{}{\thesection\ $\blacklozenge$ \textsc{\rightmark}}}
\fancyfoot[C]{}

\begin{document}
\part{Part One}
\chapter{Ch01}
\section{One Point One}
\lipsum[1-5]
\section{One Point Two}
\lipsum[9-11] \vspace{3in} \lipsum[12-13]
\section{One Point Three}
\lipsum[18-20]
\end{document}

• I see no reason for this, so a minimal example is needed. In the meantime, \fancyplain{}{...} should just be ... and \textsl{\textsc{...}} should just be \textsc{...} (\textsl does nothing at all if the fonts don't have slanted small caps). – egreg Jul 21 '17 at 20:59
• I will try to recreate this in a minimal example and update my question accordingly. – Jacob House Jul 21 '17 at 21:03
• @JacobHouse Check if section 2.4 is actually available at the bottom of the page. If this is the case, then this behavior is normal. If not, then you have something wrong in the code or packages conflict. We need a minimal working example that is self-contained and allow us to run the code successfully getting the output you posted in the picture. – Al-Motasem Aldaoudeyeh Jul 21 '17 at 21:08

From the code snippet you posted and the outputs you provided, I guess that you have another section beginning close to the page where the incorrect header is shown. This is a common issue in LaTeX. You should not use \thesection in your headers because of this.

This might happen when LaTeX decides to break a page after the next section command took effect but does go on the next page.

To circumvent this problem, you should put \thesection into your \sectionmark definition:

\documentclass[11pt, letterpaper,twoside,openright]{report}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage[margin=1.54in]{geometry}
\usepackage{amssymb}
\usepackage{lipsum}

\pagenumbering{arabic}
\setcounter{page}{1}
\pagestyle{fancy}
\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ $\blacklozenge$ \textsc{#1}}}
\fancyfoot[C]{}