# Headers with fancyhdr (or others): Chapter on odd pages, Section and Subsection on even pages

I'm using a double sided report for my thesis and in the headers I want to show: Chapter number and name (on the left) on odd pages; Section number and name (on the left) and Subsection number and name (on the right) on even pages. If there is no subsection I want to display only the section. Example, if you run the code below I would like to have:

• on page 9: 1.3 Mechanical characterization (as there is no subsection)
• on page 10: Chapter 1. Experimental section (ok)
• on page 11: 1.3 Mechanical characterization (on the left) 1.3.1 Tensile tests (on the right)

I tried \renewcommand solution, suggested by several users but it still doen't work:

\renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}}

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

\renewcommand{\subsubsectionmark}[1]{\markright{\thesubsubsection\ ##1}}


This is my code, every chapter contains several sections and subsections:

    \documentclass[openright, twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{geometry}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage[sorting=none]{biblatex} %Imports biblatex package
\addbibresource{references.bib} %Import the bibliography file
\usepackage{indentfirst}
\usepackage{tabularx}
\usepackage{multirow} %Required for multirows
\usepackage{enumerate}
\usepackage[skip=5pt]{caption}
\usepackage{subcaption}
\usepackage{blindtext}

\newcommand\blankpage{%
\null
\thispagestyle{empty}%
\newpage}

\newgeometry
{
top=2.5cm,
bottom=2cm,
outer=2cm,
inner=2cm,
}
\usepackage{fancyhdr}

\renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}}

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

\renewcommand{\subsubsectionmark}[1]{\markright{\thesubsubsection\ ##1}}

\begin{document}
\setlength{\parskip}{0pt}

\tableofcontents
\listoffigures
\listoftables
\afterpage{\null\newpage}
\newpage

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}

\chapter{Experimental section}
\section{Examined membranes}
\label{examined_CM_section}
\blindtext
\section{Structural characterization}
\blindtext
\subsection{Methodological and experimental details}
\blindtext
\subsection{Results}
\blindtext
\section{Mechanical characterization}
\blindtext\blindtext\blindtextblindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext\blindtext
\blindtext \blindtext \blindtext
\subsection{Tensile tests}
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext \blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext
\blindtext\blindtext\blindtext \blindtext \blindtext \blindtext

\subsubsection{Methodological and experimental details}
\blindtext
\subsubsection{Results}
\blindtext
\subsubsection{Comparison of different membranes}
\subsection{Fracture mechanics tests}
\subsubsection{Methodological and experimental details}
\paragraph{Determination of $\eta_{pl}$}
\paragraph{Essential work of fracture approach}
\subsubsection{Results}
\subsubsection{Comparison of different membranes}
\end{document}


I put the \pagestyle{fancy} command after \tableofcontents, \listoffigures, \listoftables because I don't want headers in this part of the document.

I'm opened to other solutions that fancydhr package.

Thank you.

• you should replace your \include with some dummy sectioning commands so that the code can be tested. But apart from this: it is normally not a good idea to show both section and subsection in a header: If a section begins on a page you could get e.g. 2.2. Section 1.3.9 Subsection which simply looks odd. And replace this curious \afterpage{\null\newpage} with \cleardoublepage. Dec 10, 2021 at 9:38
• Your code can't even work because of the ##1. Dec 10, 2021 at 10:19
• You should run your code before putting it here, so that you can remove the errors first. Dec 10, 2021 at 11:01

In your headers you have three pieces of information: chapter, section and subsection. Standard LaTeX only has two marks, \leftmark and \rightmark, so this doesn't fit. Fortunately, chapters always start at a new page, so you can put the chapter header in a macro, and then you can use \leftmark for section and \rightmark for subsection.


\newcommand{\chaptertitle}{}
\renewcommand{\sectionmark}[1]{\markboth{\thesection\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{\thesubsection\ #1}}

\pagestyle{fancy}
\fancyhf{}