Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ;)

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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:

enter image description here

share|improve this answer
    
this works ;) thanks –  user46007 Feb 16 at 16:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.