10

I am writing a maths book for A level students using the class book, and I am completely new to LaTeX, so please bear with me if this is trivial. I have written a simplified version of my code down here. When I execute it, there is a blank page with the fancy header with the horizontal bar. How can make the header blank? I think the whole CONTENTS and then CONTENTS again thing looks rather silly.

\documentclass{book}
\usepackage{fancyhdr}
\title{First Year Pure Mathematics}
\author{Luke Collins and Sandro Grech}
\date{}
\fancypagestyle{front}{%
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot[C]{\thepage}
}
\fancypagestyle{main}{%
    \fancyhf{}
    \fancyhead[LE,RO]{\slshape \rightmark}
    \fancyhead[LO,RE]{\slshape \leftmark}
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0.4pt}        
}
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyhead{}
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
}
\begin{document}
\pagenumbering{gobble}
\pagestyle{empty}
\maketitle
\pagestyle{front}
\frontmatter
\chapter{Preface}
text
\chapter{How to use this book}
text

\mainmatter
\tableofcontents
\pagestyle{main}
\chapter{Logical Foundation}
    rest of book
\end{document}
3
  • You can use \thispagestyle for specific page. in this case you can write \thispagestyle{empty} in the page that you want ...
    – juanuni
    May 25, 2015 at 20:47
  • Always use \cleardoublepage before changing \pagestyle (but \frontmatter and \mainmatter issue it). In my opinion the table of contents should be in the front matter, particularly if it uses the same page style as in the front matter. Also avoid \pagenumbering{gobble}, you'll regret it if you add hyperref; better removing the page number by applying a suitable page style. You may want to consider loading emptypage for making completely empty pages added by \cleardoublepage.
    – egreg
    May 25, 2015 at 21:08
  • I think this is basically a duplicate of the following: tex.stackexchange.com/questions/246505/… However, I'm not flagging as a duplicate because Werner's answer gives a lot of great information that the other thread doesn't. In other words, the question is a duplicate; but the answer adds a lot of value. May 26, 2015 at 3:02

3 Answers 3

8

This is actually due to an incorrect use of your timing in setting the \pagestyle.

Since the ToC is set under the front page style, and the main document should be processed under main, you should use

\chapter{Logical foundation}
\pagestyle{main}

rather than the other way around. That is, you chapter is first set (the heading; this actually includes a \cleardoublepage to start on an odd page under the book class), then you set the page style to be main.


In the hypothetical instance where you have a non-empty page style (header) as part of the ToC, you can issue the following to ensure a purely blank page (if it exists) at the end of the ToC:

\tableofcontents

\clearpage
\ifodd\value{page}\else
  \thispagestyle{empty}
\fi

\clearpage makes sure you move to the next page where you then check whether you're on an odd/even page. If you're on an even page (the false clause when checking \ifodd\value{page}), then issue \thispagestyle{empty}.

The empty page style has no header or footer. Of course, you can create a new page style for such pages. The above is just an example of how to manage that.

3

A little too late, but I found a working solution, apply \pagestyle{empty} before the TOC and restore it to \pagestyle{fancy} afterwards:

\pagestyle{empty}
\tableofcontents
\newpage
\pagestyle{fancy}

If you need to remove/change the whitespace that remains on the header area when applying \pagestyle{empty}, you can apply a new geometry and then restore it afterwards:

%You can choose your values for the margins.

\newgeometry{top=1in, bottom=1in, left=1in, right=1in}
\pagestyle{empty}
\tableofcontents
\restoregeometry
\pagestyle{fancy}

There's no need to use \newpage as \restoregeometry already applies \pagebreak

0

This is works...

% REMOVE HEADER CONTENTS
\addtocontents{toc}{\protect\thispagestyle{empty}}
1
  • 4
    Please do not only post a snippet of code out of context but integrate it into a MWE and explain why it works.
    – TeXnician
    Jul 3, 2020 at 8:02

You must log in to answer this question.

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