[Tex/LaTex] Change header for Frontmatter

front-matterheader-footer

In the MWE below, I wanted to be able to show the name of the chapter on pages in the \frontmatter that spans more than one page. In the example, the "Dedication", "List of Abbreviations" and the "Nomenclature" pages. Instead of showing "Contents" on the \frontmatter pages, show "Dedication", then "List of Abbreviations" and then "Nomenclature" on the respective pages. The first page after the chapter start page should have the name of the chapter, then the second page following the chapter start page should have the name of the book.

Here is the code that I have so far:

\documentclass{book}
\usepackage{lipsum}
\usepackage{etoolbox,fancyhdr}

\newcommand{\mymark}{}

\makeatletter
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}}
\fancyhf{} \fancyhead[LE,RO]{\textbf{\sffamily\normalsize\thepage}}
\fancyhead[LO]{\rightmark}
\fancyhead[RE]{\textbf{\sffamily\scshape \leftmark}}%
\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

\renewcommand{\mymark}{\leftmark}


\begin{document}

\frontmatter
\tableofcontents 

\chapter*{Dedication}
\lipsum[1-6]

\chapter*{List of Abbreviations}
\lipsum[1-6]

\chapter*{Nomenclature}
\lipsum[1-6]

\part{Part One}
\mainmatter
\fancyhead[RE]{\textbf{\sffamily\scshape\chaptername~\thechapter. \leftmark}}%
\chapter{This is Start of Main Text}
\section{Section One}
\lipsum[1-11]

\end{document}

Best Answer

May be I do not completely understand what the desired result is. But if you use starred chapters like \chapter*{Dedication} you have to manually set the marks.

\documentclass{book}
\usepackage{emptypage}
\usepackage{lipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

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

\fancyhead[LE,RO]{\bfseries\sffamily\normalsize\thepage}
\fancyhead[LO]{\bfseries\sffamily\normalsize\rightmark}
\fancyhead[RE]{\bfseries\sffamily\normalsize\leftmark}

\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}

\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

\begin{document}
\frontmatter
\tableofcontents 

\chapter*{Dedication}\markboth{Dedication}{}
\lipsum[1-6]
\chapter*{List of Abbreviations}\markboth{List of Abbreviations}{}
\lipsum[1-6]
\chapter*{Nomenclature}\markboth{Nomenclature}{}
\lipsum[1-6]

\mainmatter
\part{Part One}
\chapter{This is Start of Main Text}
\section{Section One}
\lipsum[1-11]
\end{document}

enter image description here

If there can be a TOC entry for chapters in frontmatter you could use \chapter instead \chapter*.

\documentclass{book}
\usepackage{emptypage}
\usepackage{lipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

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

\fancyhead[LE,RO]{\bfseries\sffamily\normalsize\thepage}
\fancyhead[LO]{\bfseries\sffamily\normalsize\rightmark}
\fancyhead[RE]{\bfseries\sffamily\normalsize\leftmark}

\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}

\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

\begin{document}
\frontmatter
\tableofcontents 

\chapter{Dedication}
\lipsum[1-6]
\chapter{List of Abbreviations}
\lipsum[1-6]
\chapter{Nomenclature}
\lipsum[1-6]

\mainmatter
\part{Part One}
\chapter{This is Start of Main Text}
\section{Section One}
\lipsum[1-11]
\end{document}
Related Question