我正在尝试fancyhdf.pdf
第 11 页的示例。但我发现我得到的标题是错误的,就像在条目Foo--Foo
的第一页上一样Foo
,但Foo
在后续页面上却是正确的。原因似乎是equal{\leftmark}{\rightmark}}
命令失败,因为\leftmark
是小写,而\rightmark
是大写。我找不到任何方法来解决这个问题。有什么建议吗?我的代码是:
\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}
这是一个完整的例子。如果没有 \renew 命令,第一页就会出现“-AAA”,而它应该出现“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}