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.

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}
share|improve this question
    
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. –  lvleph Apr 16 '12 at 11:25
1  
\preptocmd should be \pretocmd I think (2x)... –  Matthias May 6 '12 at 11:11
add comment

1 Answer

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.

share|improve this answer
    
Yeah the problem is that appendix may come before the bibliography or after. –  lvleph 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. –  lvleph Apr 15 '12 at 18:38
add comment

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.