# Fancyhdr messes up with \backmatter

I just found out that if fancyhdr has to mention a chapter located in \backmatter, it does this by numbering it with the number of the last chapter.

For instance, this:

\documentclass[11pt, a4paper, oneside]{book}

\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}

\begin{document}

\mainmatter

\chapter{asd}
\lipsum

\chapter{asd2}
\lipsum

\chapter{asd3}
\lipsum

\backmatter

\chapter{conclusions}
\lipsum

\end{document}


ends up in having a "CHAPTER 3: CONCLUSIONS" written in the top-right part of the last page. First of all, this is the fourth chapter, but since we are in \backmatter the chapter shouldn't be numbered at all anyway.

So what I want to do is to correct this so that fancyhdr, just for the chapters in \backmatter, doesn't write that "CHAPTER X: ", and just writes the name of the chapter.

I found this other solution, but both the option proposed ends up in having chapter written in normal font, instead of caps. I tried to set everything in caps by using \MakeUppercase and \textsc in various places of the first code proposed, but I get errors everywhere, so I'm still wondering how to do that.

Thanks to anybody who'll help me ;)

-

Roughly speaking, fancyhdr defines \chaptermark using

\def\chaptermark#1{\markboth {\MakeUppercase{\ifnum \c@secnumdepth>\m@ne
\@chapapp\ \thechapter. \ \fi #1}}{}}:


that only checks for the value of secnumdepth to decide whether or not to add "Chapter #" to the mark. You need then to perform an additional test and use this definition in the \mainmatter chapters, and another one, removing "Chapter #" for chapters not in the \mainmatter section:

\makeatletter
\renewcommand\chaptermark[1]{
\markboth{\MakeUppercase{%
\ifnum\c@secnumdepth>\m@ne\if@mainmatter
\@chapapp\ \thechapter. \ \fi\fi #1}}{}%
}
\makeatother


A complete example using small caps:

\documentclass[11pt, a4paper, oneside]{book}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}

\makeatletter
\renewcommand\chaptermark[1]{
\markboth{\textsc{%
\ifnum\c@secnumdepth>\m@ne\if@mainmatter
\@chapapp\ \thechapter. \ \fi\fi #1}}{}%
}
\makeatother

\begin{document}

\mainmatter

\chapter{asd}
\lipsum

\chapter{asd2}
\lipsum

\chapter{asd3}
\lipsum

\backmatter

\chapter{Conclusions}
\lipsum

\end{document}


An image of the header for the last page:

-
this works ;) thanks –  user46007 Feb 16 at 16:18