# Headers and footers style issue in article with multiple chapter types

I am writing a document with different chapter types : the first two are fore-chapters (Abstract, Dedication) and have empty headers, the following four chapters belong to the core text and do have headers, then I have an appendix section with three chapters (A, B and C) with headers and then the bibliography chapter as inserted using BibTex \bibliography.

The issue is that the last appendix has its last page with a header named "Chapter 4" instead of Appendix C and the Bibliography chapter has a header also named "Chapter 4" although I would prefer empty headers like for the first two chapters.

I guess the issue comes from the way I declared the header and footer style. Especially in:

\fancyhead[LE,RO]{\ifnum\value{chapter}>0 \chaptername \hspace{0.05cm} \thechapter \fi}


I don't know how to specify "greater than 0 and lower than 5". But maybe the issue comes from elsewhere? Any idea?

Here is my MWE:

\documentclass[twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[toc,page]{appendix}
\usepackage{comment}
\usepackage[explicit]{titlesec}

% Chapter styles
%-----------------------------------------------------------------
\usepackage{lmodern}
\newlength\chapnumb
\setlength\chapnumb{4cm}

\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\fontsize{120}{110}\selectfont\thechapter}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\LARGE#1}\\
\rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\titleformat{name=\chapter,numberless}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\mbox{}}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\LARGE#1}\\
\rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}

% Header and footer styles
%-----------------------------------------------------------------
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\fancyhead[LE,RO]{\ifnum\value{chapter}>0 \chaptername \hspace{0.05cm} \thechapter \fi}

\fancyfoot[LE,RO]{\thepage}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}

% Bibliography style
%-----------------------------------------------------------------
\usepackage{natbib}
\bibliographystyle{apa}

% DOCUMENT
%-----------------------------------------------------------------
\begin{document}

\chapter*{Abstract}
\lipsum[1-5]

\chapter*{Declaration}
\lipsum[1-5]

\chapter{Chapter1}
\lipsum[1-12]

\chapter{Chapter2}
\lipsum[1-12]

\chapter{Chapter3}
\lipsum[1-12]

\chapter{Chapter4}
\lipsum[1-12]
\citep{BibTest}

\begin{appendices}
\renewcommand\chaptername{Appendix}

\chapter{Hello}
\lipsum[1-10]

\chapter{Beautiful}
\lipsum[1-10]

\chapter{World}
\lipsum[1-18]
\end{appendices}

\bibliography{sample.bib}

\end{document}


And here is the BibTex reference in a bib file called "sample.bib":

@Article{BibTest,
author =       "Anonymous, Peter and Baker, Steven",
title =        "\lipsum[1-10]",
journal =      "Journal of tests",
year =         "1988",
volume =       "19",
number =       "9",
pages =        "897--915"
}

• Welcome to TeX.SE. To me, the \bibliography command belongs logically into the appendix. In your MWE, the bibliography follows the appendix, which is crude. Class book offers the \appendix command. Using that, the chapters in the appendix will get be numbered "A", "B", ... Maybe, you don't need fancy headers? I just removed those definitions and stated \pagestyle{headings} in your document, which helped a lot.
– Jan
Dec 5, 2019 at 19:28

Once you close the appendices environment, any definitions made within that group that are not global disappears. For example, your \renewcommand{\chaptername}{Appendix} doesn't exist after \end{appendices}. And, since \end{appendices} doesn't close off (or ships out) the page, any headers that are set after it may revert back to previous definitions. That's exactly what you're seeing.

One solution would be to forcefully ship out the page before closing the appendices environment, as in

\begin{appendices}

\clearpage % ...or \cleardoublepage
\end{appendices}


With regards to the header, you have the following:

\fancyhead[LE,RO]{%
\ifnum\value{chapter}>0
\chaptername\space \thechapter
\fi
}


which should work for all of your chapters. That is, it excludes adding any content for the "fore-chapters", since they don't increase the chapter counter, and therefore fall within the \value{chapter}<0 range. However, if you have more than 3 chapters (the number in your appendix), it's difficult to make this jive well with having the Bibliography at the end (technically chapter 4 after the 3 appendix chapters). For example, if you instead used

\fancyhead[LE,RO]{%
\ifnum\value{chapter}>0
\ifnum\value{chapter}<4
\chaptername\space \thechapter
\fi
\fi
}


you have combined condition \value{chapter}>0 and \value{chapter}<4, but you will love any headers associated with chapters 4+ before your appendix. Instead, I'd suggest creating a new page style for the bibliography altogether:

\fancypagestyle{bibliographypagestyle}{%

\pagestyle{bibliographypagestyle}