I cannot find in any latex forums a solution for my problem with chapter-specific headers.
I am compiling a one-sided report with various chapters. For all the chapters, I have the header showing the chapter's number and title. But for one of them I would like to have the header showing the section's number and title instead (this is due to the nature of that particular chapter, which is longer than the others).
Everything works fine and I manage to show the section in the header. However, all the following chapters will not go back to the initial settings that shows the chapter in the header.
This is a minimal example with 3 chapters and you can run it to see the results. Chapter 1 and 3 should show the chapter in the header and only Chapter 2 is supposed to have the sections in its header. But Chapter 3 keeps applying the settings of the preceding although I've changed them.
I try resetting to \pagestyle{plain}
or \pagestyle{empty}
before adding the \renewcommand{\chaptermark}
but it doesn't work.
\documentclass[11pt,a4paper,oneside]{report}
\usepackage{fancyhdr}
\begin{document}
\pagestyle{fancy}
\fancyhead{} % clear all header fields
\fancyhead[LO,LE]{\leftmark}
\renewcommand{\chaptermark}[1]{%
\markboth{\thechapter.\ #1}{}}
\chapter{My First Chapter}
\section{Section 1}
\clearpage
\section{Section 2}
\clearpage
\section{Section 3}
\clearpage
\renewcommand{\sectionmark}[1]{%
\markboth{\thesection.\ #1}{}}
\chapter{My Second Chapter}
\section{Section 1}
\clearpage
\section{Section 2}
\clearpage
\section{Section 3}
\clearpage
\renewcommand{\chaptermark}[1]{%
\markboth{\thechapter.\ #1}{}}
\chapter{My Third Chapter}
\section{Section 1}
\clearpage
\section{Section 2}
\clearpage
\section{Section 3}
\clearpage
\end{document}
Best Answer
Define two page styles:
Don't forget to modify
\headheight
as suggested during compilation: