I would like to customize my headers in the following way in a book:
- On non-text pages (like for example part titles, or chapter title pages): no header, no footer
- On text pages
- On even pages: page number on the left, chapter title on the right, in the format
Chapter 1: Title
(in bold, grey). If not in a chapter, part title. If not in a part, book title. - On odd pages: page number on the right, section title on the left in the format
Title
(in bold, grey). If not in a section, chapter title. If not in a chapter, part title. If not in a part, book title.
- On even pages: page number on the left, chapter title on the right, in the format
How to achieve this with fancyhdr
?
Starting document:
\documentclass[twoside, 10pt]{book}
\usepackage[
paperwidth=6in,
paperheight=9in,
tmargin=0.75in,
bmargin=0.75in,
inner=0.75in,
outer=0.75in
]{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{tabularx}
\usepackage[listings,skins,theorems,breakable,most]{tcolorbox}
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage[parfill]{parskip}
\restoreparindent
\pagestyle{fancy}
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO]{\nouppercase\rightmark}
\fancyhead[RE]{\nouppercase\leftmark}
\cfoot{}
\renewcommand{\headrulewidth}{}
\renewcommand{\footrulewidth}{}
\begin{document}
\tableofcontents
\chapter{This is a chapter name}
\chaptertoc
\lipsum
\section{First section}
\subsection{First subsection}
\lipsum
\subsection{Second subsection}
\lipsum
\section{Second section}
\subsection{First subsection}
\lipsum
\subsection{Second subsection}
\lipsum
\section{Second section}
\subsection{First subsection}
\lipsum
\subsection{Second subsection}
\lipsum
\end{document}
Best Answer
You should redefine \headrulewidth to 0pt, not to empty. Beside this you only need to set the correct marks: