The fancyhdr
package provides, by default, the definition of \chaptermark
used in report.cls
when \pagestyle{headings}
is in force.
The book
class instead has a check for \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}}}}
So you should supplement your code with the right definition. There's still a small problem, in that the pages of the table of contents will have two “CONTENTS” in the header, because \tableofcontents
uses \@mkboth
; you can fix it by redefining it.
\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}
fancy
uses the ruled header style, with\thechapter
etc. information. Sincefrontmatter
disables the numbering, the chapter number is still0
. Either redefine the headings or apply\pagestyle{fancy}
after the abstract chapter