[Tex/LaTex] How to re-define the chapter-mark without changing the Appendix heading

fancyhdrheader-footer

The document is book class and the Appendix is added by:

 ...
\backmatter 
\appendix
\chpater{Appendix A}
  ...
\chpater{Appendix B}
  ...

Using fancyhdr:

\usepackage[]{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead{} 

\renewcommand{\sectionmark}[1]{\markright{\thesection ~ \ #1}}
\renewcommand{\chaptermark}[1]{\markboth{ \chaptername\ \thechapter ~ \ #1}{}} 

%head setting
\fancyhead[LE]{\textcolor{black} {\thepage}}
\fancyhead[RE]{\textcolor{black} {\itshape \nouppercase  \leftmark}}%higher level \scshape  \MakeUppercase
\fancyhead[LO]{\textcolor{black} {\itshape \nouppercase  \rightmark}} 
\fancyhead[RO]{\textcolor{black} {\thepage}}   %odd page

The chapter-mark is expected to be re-defined like Chapter 2 State of the art, However, the \chaptername will appear in Appendix heading.

So how to solve this issue?

enter image description here

Best Answer

Add a test for the mainmatter switch to the definition of \chaptermark.

\documentclass{book}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead{} 

\makeatletter
\renewcommand{\sectionmark}[1]{\markright{\thesection~~#1}}
\renewcommand{\chaptermark}[1]{\markboth{\if@mainmatter\chaptername\ \thechapter~~\fi#1}{}}
\makeatother

\fancyhead[LE]{\thepage}
\fancyhead[RE]{\itshape\nouppercase  \leftmark}
\fancyhead[LO]{\itshape\nouppercase  \rightmark}
\fancyhead[RO]{\thepage}

\usepackage{lipsum}

\begin{document}

\backmatter

\chapter{Appendix~A}

\lipsum[1-12]

\end{document}‚Äč
Related Question