使用 fancyhdr 从 frontmatter 章节标题中删除“CHAPTER 0.”

使用 fancyhdr 从 frontmatter 章节标题中删除“CHAPTER 0.”

正如标题所示。摘要后面的标题如下:

CHAPTER 0. ABSTRACT

如何从前言标题中删除不必要的章节编号?

\documentclass{book}
\usepackage{fancyhdr}
\begin{document}
\frontmatter
\pagestyle{fancy}
\chapter{Abstract}
Why does it say ``Chapter 0.'' on the next page?
\tableofcontents
\mainmatter
\chapter{First}
\end{document}

答案1

fancyhdr包默认提供了\chaptermark何时report.cls生效的定义\pagestyle{headings}

该类book反而检查了\if@mainmatter

  \def\ps@headings{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty
      \def\@evenhead{\thepage\hfil\slshape\leftmark}%
      \def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth {\MakeUppercase{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter. \ %
          \fi
        \fi
        ##1}}{}}%
    \def\sectionmark##1{%
      \markright {\MakeUppercase{%
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}}

因此,你应该用正确的定义补充你的代码。还有一个小问题,目录的页面将有标题中的“CONTENTS”,因为\tableofcontents使用\@mkboth;您可以通过重新定义来修复它。

\documentclass{book}
\usepackage{fancyhdr}
\begin{document}
\pagestyle{fancy}
\makeatletter
\renewcommand\chaptermark[1]{%
  \markboth{\MakeUppercase{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \@chapapp\ \thechapter. \ %
      \fi
    \fi
    #1}}{}%
}
\renewcommand\@mkboth[2]{\markboth{#1}{}}
\makeatother

\frontmatter
\chapter{Abstract}
Why does it say ``Chapter 0.'' on the next page?
\tableofcontents
\mainmatter
\chapter{First}
\end{document}

相关内容