6

What I am trying to accomplish is a fancyhdr that places Appendix or Bibliography in the header with one single definition. So if I am in the bibliography it should display Bibliography, but should display Appendix otherwise.

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{etoolbox}

\newcommand{\backmatter}{
    \fancyhdr[C]{\ifstrequal{\leftmark}{\MakeUppercase{\bibname}}
        {\bibname}{\appendixname\ \thechapter}}

\begin{document}
   \backmatter       
   \bibliography{my.bib}
   \appendix
   \chapter{Appendix}
\end{document}

The ifstrequal always evaluates as false and so always produces Appendix in the header. Thank you in advance for your help.

EDIT: My new solution is as follows

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{etoolbox}

\preptocmd{\bibliography}{\fancyhead[C]{\bibname}}{}{}
\preptocmd{\appendix}{\fancyhead[C]{\appendixname\ \thechapter}}{}{}

\begin{document}       
   \bibliography{my.bib}
   \appendix
   \chapter{Appendix}
\end{document}

However, when my bibliography hits the third page it displays Appendix again.

Edit 2: The following works

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{etoolbox}

\preptocmd{\bibliography}{\cleardoublepage \fancyhead[C]{\bibname}}{}{}
\preptocmd{\appendix}{\cleardoublepage \fancyhead[C]{\appendixname\ \thechapter}}{}{}

\begin{document}       
   \bibliography{my.bib}
   \appendix
   \chapter{Appendix}
\end{document}
  • The page breaks may indeed give timing problems. I'd simply set the header explicitly in the document. – egreg Apr 15 '12 at 19:31
  • I am making a class file for other people to use on their thesis, so that is an option but sort of defeats the purpose. Thank you for the suggestion. – erichlf Apr 16 '12 at 11:25
  • 1
    \preptocmd should be \pretocmd I think (2x)... – Matthias May 6 '12 at 11:11
6

The main problem is that \leftmark doesn't contain \MakeUppercase{\bibname}, but a more complicated thing. There are also other expansion problems.

If your backmatter is in that form, I suggest

\newif\ifbiblio
\newcommand{\backmatter}{%
  \fancyhead[C]{\ifbiblio \bibname\else\appendixname\ \thechapter\fi}%
  \bibliotrue
}
\appto\appendix{\clearpage\bibliofalse}

The conditional will be true from \backmatter until after the page change for the start of the appendices.

  • Yeah the problem is that appendix may come before the bibliography or after. – erichlf Apr 15 '12 at 18:20
  • I could always just prepend and append to bibliography, but I can't seem to figure out how to do this. – erichlf Apr 15 '12 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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