I am trying the fancyhdf.pdf
page 11 example. But I find I am getting wrong headers like Foo--Foo
on the first page of the Foo
entry, but correctly Foo
on subsequent pages. The reason seems to be that the equal{\leftmark}{\rightmark}}
command is failing because \leftmark
is lower case, and \rightmark
is upper case. I cannot find any way to fix this. Any suggestions? My code is:
\renewcommand{\parishmarks}{% as in fancyhdr.pdf page 11, but with \nouppercase added
\ifthenelse{\equal{\leftmark}{\rightmark}}{\rightmark}{\nouppercase\rightmark--\leftmark}}
\fancyhead[L]{\chaptermark}\fancyhead[R]{\parishmarks}
See How can I achieve dictionary headers for two page spreads in LaTeX
Here is a complete example. Without the \renewcommand, the first page has "-AAA" where it should have "AAA".
\documentclass[12pt,a4paper]{article}
\usepackage{fancyhdr,ifthen}
\renewcommand{\sectionmark}[1]{} % turn off section marks
% create a command to create marks and collapse them if they are identical...
\newcommand{\mymarks}{%
\ifthenelse{\equal{\leftmark}{\rightmark}}
{\rightmark} % if equal
{`\rightmark'--`\leftmark'}} % if not equal
\renewcommand{\mymarks}{% fix the case where \rightmark is an empty string \ifthenelse{\equal{\leftmark}{\rightmark}}
{\rightmark} % if equal
{\ifthenelse{\equal{}{\rightmark}}{\leftmark}{\rightmark--\leftmark}}} % if not equal
\fancyhead[LE,RO]{\mymarks}
\fancyhead[LO,RE]{\thepage}
\pagestyle{fancy}
\begin{document}
\section{First section}\markboth{AAA}{AAA} % this goes wrong without the fix
\noindent This is the first section.
\clearpage\markboth{CCC}{BBB}
\noindent This is a new page, not a new section.
\end{document}