Remove CHAPTER 0.' from header in frontmatter chapters with fancyhdr

As the title says. The heading on the page following the Abstract looks like this:

CHAPTER 0. ABSTRACT

How can I remove the unnecessary Chapter number from the headings in the frontmatter?

\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}
• fancy uses the ruled header style, with \thechapter etc. information. Since frontmatter disables the numbering, the chapter number is still 0. Either redefine the headings or apply \pagestyle{fancy} after the abstract chapter – user31729 Jan 31 '16 at 17:08

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:

\let\@oddfoot\@empty\let\@evenfoot\@empty
\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}