2

I wanted to tweak the standard header. [I found the solution - see below]

Here's standard code with PDFLaTeX:

\documentclass{book}
\usepackage{lipsum}

\begin{document}
\frontmatter   %Used for book class
\tableofcontents
\chapter{Introduction}
\lipsum
\lipsum

\mainmatter
\chapter{First Chapter}
\lipsum
\lipsum
\chapter{Second Chapter}
\lipsum
\lipsum
\chapter{Third Chapter}
\lipsum
\lipsum

\backmatter
\chapter{Afterword}
\lipsum
\lipsum
\end{document}

This creates a nice looking header with

  • page number Even Left (EL) and Odd Right (OR)
  • "INTRODUCTION" and "CHAPTER 1: FIRST CHAPTER" and "AFTERWORD" in ER
  • Nothing in OL

Note that "CHAPTER #: " is prepended to the Chapter name automatically.

What I would like is to have:

  • page number Even Left (EL) and Odd Right (OR)
  • "BOOK TITLE" in ER
  • "INTRODUCTION" and "CHAPTER 1: FIRST CHAPTER" and "AFTERWORD" in OL

And an alternative for consideration of: - "INTRODUCTION" and "FIRST CHAPTER" and "AFTERWORD" in OL

I tried including this in the preamble:

%https://www.sharelatex.com/learn/Headers_and_footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{BOOK TITLE}
\fancyhead[LO]{\leftmark}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

But here the problem was that it created:

  • "CHAPTER 0: INTRODUCTION" and "CHAPTER 1: FIRST CHAPTER" and "CHAPTER 3: AFTERWORD" in OL (bizarrely, since the afterword is the fourth chapter).
3
  • \mainmatter prevents counting of structure elements, so \thechapter will print 0 still for Introduction.
    – user31729
    Aug 31, 2017 at 22:09
  • Sorry, I meant \frontmatter...
    – user31729
    Aug 31, 2017 at 22:19
  • 1
    Instead of editing your question adding the solution, you could post an answer, thank you!
    – CarLaTeX
    Sep 1, 2017 at 7:10

1 Answer 1

1

I dug into p10 of the fancyhdr package documentation, and I can remove the words "CHAPTER #: " by adding

\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}

I hadn't realized this, but you can just renewcommand anywhere in your document, so you can tweak this kind of stuff on the fly. So this solves my problem, and is flexible enough for all cases:

\documentclass{book}
\usepackage{lipsum}

%https://www.sharelatex.com/learn/Headers_and_footers
%THIS SETS UP THE GENERAL FORMAT. INCLUDES AUTOMATIC TWEAKS FOR TITLE PAGES.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\textsc{Book Title}}  <---Makes Title Small Caps
\fancyhead[LO]{\leftmark}
\renewcommand{\headrulewidth}{0pt}  %<--Removes lines that come with fnyheader
\renewcommand{\footrulewidth}{0pt}


\begin{document}
\frontmatter   %Used for book class
\renewcommand{\chaptermark}[1]{\markboth{\textsc{#1}}{}} %<---------
                           %THIS MAKES THE \leftmark FORMAT WITH
                           %SMALLCAPS & NO CHAPTER NUMBERING
                           %AND WILL BE USED FOR ALL FRONT MATTER
\tableofcontents
\chapter{Introduction}
\lipsum
\lipsum

\mainmatter
\renewcommand{\chaptermark}[1]{\markboth{\textsc{\chaptername\ \thechapter.\ #1}}{}}  %<---------
                           %THIS MAKES THE \leftmark FORMAT WITH
                           %SMALLCAPS & INCLUDE "CHAPTER ##: "
                           %AND WILL BE USED FOR ALL MAIN MATTER
\chapter{First Chapter}
\lipsum
\lipsum
\chapter{Second Chapter}
\lipsum
\lipsum
\chapter{Third Chapter}
\lipsum
\lipsum

\backmatter
\renewcommand{\chaptermark}[1]{\markboth{\textsc{#1}}{}} %<---------
                           %THIS MAKES THE \leftmark FORMAT WITH
                           %SMALLCAPS & NO CHAPTER NUMBERING
                           %AND WILL BE USED FOR ALL BACK MATTER
\chapter{Afterword}
\lipsum
\lipsum
\end{document}

Hopefully this will be useful to other people doing this. I'm looking at you, future self, who will have completely forgotten all this in a few years.

Here are some screenshots of the resultant headers:

Introduction header

Chapter header

Afterword header

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .