3

I have a header created with fancyhdr. It repeats on all the pages including Table of Contents and Preface sections. I tried to use \thispagestyle{empty} but it only works on the first page while I need to clear it in the frontmatter

\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\renewcommand\headrulewidth{1.5pt}
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
        \hrule\@height\headrulewidth\@width\headwidth
        \vskip 2pt% 2pt between lines
        \hrule\@height.5pt\@width\headwidth% lower line with .5pt line width
        \vskip-\headrulewidth
        \vskip-1.5pt}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\thispagestyle{empty}
\frontmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Table of contents

\tableofcontents
\chapter{Preface}
\lipsum
\lipsum
\mainmatter
\chapter{Ch1}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\chapter{ch2}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\end {document}
2
  • Do you really want empty style or only roman page numbers, without rules?
    – Bernard
    Commented Jun 7, 2016 at 11:42
  • @Bernard I am still not sure about the standard, what if I want to remove the chapter title and numbering from the header, while keeping the lines...
    – Ahmad
    Commented Jun 7, 2016 at 11:52

2 Answers 2

7

change this one

\thispagestyle{empty}

to

\pagestyle{empty}

and insert \pagestyle{fancy} here

\mainmatter
\chapter{Ch1}

It will looks now like

\mainmatter
\pagestyle{fancy}
\chapter{Ch1}
1

Is this what you'want? In front matter, there's only chapter title (Contents/Preface), first chapter pages and white pages have empty style (for the whole document). I added the twoside option, and used the emptypage and xpatche packages to achieve that.

\documentclass[11pt, twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{xpatch, emptypage}%
 \pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\renewcommand\headrulewidth{1.5pt}
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
        \hrule\@height\headrulewidth\@width\headwidth
        \vskip 2pt% 2pt between lines
        \hrule\@height.5pt\@width\headwidth% lower line with .5pt line width
        \vskip-\headrulewidth
        \vskip-1.5pt}}
\makeatother

%%
\xpatchcmd{\chapter}{%
\thispagestyle{plain}}{%
\thispagestyle{empty}}{}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\frontmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Table of contents
\tableofcontents
\chapter*{Preface}
\markboth{Preface}{Preface}
\addcontentsline{toc}{chapter}{Preface}
\lipsum
\lipsum[1-4]
\mainmatter
\pagestyle{fancy}
\chapter{Ch1}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\chapter{ch2}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\end {document} 

enter image description here enter image description here enter image description here

You must log in to answer this question.

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