5

In the first pages of the Table of Contents, List of Figures, etc, I want to remove the chapter name from the header, but I want to to keep the chapter name/title in the header line of the following pages related to the current ToC/LoF. I tried \pagestyle{empty} for the TOCs; however, the pages following the Contents page for example, in the code given below, there is no header or footer. Is there a workaround for this? That is, how to recover the headers and footers on the 2nd page of the TOC?

Here is the code that I have:

\documentclass[11pt,openany]{book}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\usepackage{blindtext}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\newif\ifchapterwidthstar
\newcommand\printchapternumber{\ifchapterwidthstar\else\thechapter\fi}
\makeatletter
\patchcmd\@chapter{\@afterheading}{\chapterwidthstarfalse\@afterheading}{}{}
\patchcmd\@schapter{\@afterheading}{\chapterwidthstartrue\@afterheading}{}{}
\makeatother
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \ifnum\value{chapter}=0
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries]  at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \end{tikzpicture}%
}
\fancyfoot[CE]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
  \end{tikzpicture}%
}
\fancyfoot[CO]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south east) {\thepage};
  \end{tikzpicture}%
}

\title{A reasonably long title}
\date{\today}
\author{The author}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}

\begin{document}
\pagestyle{empty}
\maketitle

\tableofcontents
\listoffigures

\pagestyle{fancy}
\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]

\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument


\appendix
\chapter{Answer 1}
\lipsum[1]

\cleardoublepage
\chapter*{References}

\end{document} 
6
  • 1
    fancyhdr complains about a wrong \headheight to begin with... And I see headers and footers
    – user31729
    Feb 28, 2017 at 19:43
  • @ChristianHupfer, there are no headers and footers on the 2nd TOC page, i.e. on page 3 of the example doc.
    – Joe
    Feb 28, 2017 at 19:55
  • 1
    Ah, your statement is misleading in the question above: You should rather say: On the 2nd page of the ToC the headers etc. are missing
    – user31729
    Feb 28, 2017 at 20:00
  • @ChristianHupfer, I made the modification to my question as per your input. Hope this statement clarifies my question?
    – Joe
    Feb 28, 2017 at 20:08
  • 1
    Quick solution: \pagestyle{fancy} before \listoffigures!
    – user31729
    Feb 28, 2017 at 20:08

2 Answers 2

4

You don't have to patch \chapter ,or \@chapter. I think it's not good practice to patch commands defined in the class file, and use titlesec. Every thing you want can be incorporated in \titleformat, if you use the numberless key for starred chapter. Here is a simplified code:

\documentclass[11pt,openany]{book}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\usepackage{blindtext}
\newif\ifchapterwidthstar
\newcommand\printchapternumber{\ifchapterwidthstar\else\thechapter\fi}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}
\setlength\headheight {14pt}
\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \ifnum\value{chapter}=0
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \end{tikzpicture}%
}
\fancyfoot[CE]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
  \end{tikzpicture}%
}
\fancyfoot[CO]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south east) {\thepage};
  \end{tikzpicture}%
}

\title{A reasonably long title}
\date{\today}
\author{The author}

\titleformat{\chapter}[display]
{\chapterwidthstarfalse\normalfont\huge\bfseries}{}{0pt}{\Huge\thispagestyle{fancy}}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}
\titleformat{name=\chapter, numberless}[display]
{\chapterwidthstartrue\normalfont\huge\bfseries}{}{0pt}{\Huge\thispagestyle{fancy}\color{white}}
\titlespacing*{name=\chapter, numberless} {0pt}{0pt}{-87pt}

\begin{document}
\pagestyle{empty}
\maketitle

\pagestyle{fancy}
\thispagestyle{empty}
\tableofcontents

\listoffigures
\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]

\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument


\appendix
\chapter{Answer 1}
\lipsum[1]

\cleardoublepage
\chapter*{References}

\end{document} 

enter image description here enter image description here

9
  • Thanks for your potential solution, but I would like to remove only the name "Contents" and "List of Figures" from the first page. Everything else should remain intact. I cannot edit my question to include an image of exactly what I wanted.
    – Joe
    Feb 28, 2017 at 21:53
  • 1
    @Joe: I understood you wanted to remove the header only. If I understand well, on the first page, you want no title and no header?
    – Bernard
    Feb 28, 2017 at 22:38
  • 1
    OK. I think I've a hack, I'll post it in a moment.
    – Bernard
    Feb 28, 2017 at 23:04
  • 1
    @Joe: Update posted. Is it more like you want?
    – Bernard
    Feb 28, 2017 at 23:19
  • 1
    @Joe: I tried a code which didn't work well (a problem with marks). Also tried to do it directly with titleps instead of fancyhdr (since you load titlesec), but didn't have time to achieve it. I'll test it again as soon as possible
    – Bernard
    Mar 3, 2017 at 17:11
3

The reason for this problem is

\patchcmd{\chapter}{\thispagestyle{plain}{\thispagestyle{fancy}}{}{}

This will cause \chapter or \chapter* to use fancy only for the first page of the chapter, but not more.

So \pagestyle{empty} has been used right before \tableofcontents, then \tablecontents switches to fancy right for the first page of the ToC, then empty is active again.

If the whole document should use fancy, it's best to replace

\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

with

\patchcmd{\chapter}{\thispagestyle{plain}}{\pagestyle{fancy}}{}{}

-- this way, the pagestyle is not switched back unless stated manually later on.

\documentclass[11pt,openany]{book}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage[headheight=15pt]{geometry}
\patchcmd{\chapter}{\thispagestyle{plain}}{\pagestyle{fancy}}{}{}


\newif\ifchapterwidthstar
\newcommand\printchapternumber{\ifchapterwidthstar\else\thechapter\fi}
\makeatletter
\patchcmd\@chapter{\@afterheading}{\chapterwidthstarfalse\@afterheading}{}{}
\patchcmd\@schapter{\@afterheading}{\chapterwidthstartrue\@afterheading}{}{}
\makeatother
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \ifnum\value{chapter}=0
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries]  at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \end{tikzpicture}%
}
\fancyfoot[CE]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
  \end{tikzpicture}%
}
\fancyfoot[CO]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south east) {\thepage};
  \end{tikzpicture}%
}

\title{A reasonably long title}
\date{\today}
\author{The author}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}

\begin{document}
\pagestyle{empty}
\maketitle

\tableofcontents
\listoffigures

\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]

\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument


\appendix
\chapter{Answer 1}
\lipsum[1]

\cleardoublepage
\chapter*{References}

\end{document} 
2
  • Thanks for your input. But how to remove the chapter name "Contents" and "List of Figures", from the header on the first page of those title pages?
    – Joe
    Feb 28, 2017 at 20:23
  • 1
    @Joe: Forgot to attack that... but you're using titlesec so that's to blame
    – user31729
    Feb 28, 2017 at 21:02

You must log in to answer this question.

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