6

In my backmatter the header appears as Chapter x: chapter-name, where x is the number (or letter if I have an appendix) of the last chapter before the backmatter. How can I make the header in the backmatter to just show chapter-name? I already modified the chaptermark according to this solution to not have the Chapter 0 in the header of the frontmatter (Removing this does not affect the header in the backmatter). How can I adapt it to not have the Chapter x in the header?

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\chaptermark}[1]{%
  \ifnum\value{chapter}>0
    \markboth{Chapter \thechapter{}: #1}{}%
  \else
    \markboth{#1}{}%
\fi}

\begin{document}

\frontmatter 
\chapter{abstract}
some text

\mainmatter
\chapter{some chapter}
some text

\appendix
\chapter{some appendix}
some text

\backmatter
\chapter{some backmatter}
some text
\newpage
some text
\newpage
some text


\end{document}
Tanja
  • 559

2 Answers2

6

You're using the wrong conditional:

\documentclass[a4paper,11pt,twoside]{book}

\usepackage{lipsum} % just for the example

\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{13.6pt} % as requested by fancyhdr's warning

\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\renewcommand{\chaptermark}[1]{%
  \if@mainmatter
    \markboth{Chapter \thechapter{}: #1}{}%
  \else
    \markboth{#1}{}%
  \fi
}
\makeatother

\begin{document}

\frontmatter 
\chapter{abstract}
\lipsum[1]

\mainmatter
\chapter{some chapter}
\lipsum[1-20]

\appendix
\chapter{some appendix}
\lipsum[1-20]

\backmatter
\chapter{some backmatter}
\lipsum[1-20]


\end{document}

In the front and back matter the conditional \if@mainmatter is set to false.

egreg
  • 1,121,712
2

If what you are looking for is defining \chaptermark in a different way depending on whether you are in the "front", "main" or "back"-matter part of the document you can modify the \frontmatter, \mainmatter and \backmatter so they change it for you as follows:

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}

\makeatletter
\g@addto@macro{\frontmatter}{
    \renewcommand{\chaptermark}[1]{%
        \markboth{#1}{}%
    }    
}
\g@addto@macro{\mainmatter}{
    \renewcommand{\chaptermark}[1]{%
        \markboth{Chapter \thechapter{}: #1}{}%
    }    
}
\g@addto@macro{\backmatter}{
    \renewcommand{\chaptermark}[1]{%
        \markboth{#1}{}%
    }    
}
\makeatother

\begin{document}

\frontmatter 
\chapter{abstract}
some text

\mainmatter
\chapter{some chapter}
some text

\appendix
\chapter{some appendix}
some text

\backmatter
\chapter{some backmatter}
some text
\newpage
some text
\newpage
some text


\end{document}

The \g@addto@macro macro appends some code to the definition of a macro; I use it here to add the corresponding redefinition of \chaptermark to each of them.

Bordaigorl
  • 15,135