I am using the book class. I want to suppress page styles (page number, header, footer) in the first page of every chapter in my mainmatter, but not in \frontmatter
– where I want to have roman numbers in the footer (right corner).
I can suppress page style in the first page of every chapter document-wide with:
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{empty}% original style: plain
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\makeatother
but this imposes a \pagestyle{empty}
in the first page of every "chapter" in the frontmatter, too, so that the TOC pages are not numbered. I want the TOC pages to be numbered, but I don't know how to do this.
MWE:
\documentclass[a4paper,11pt,titlepage,oneside,openany]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{kantlipsum}
% empty style for the first page of every chapter
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{empty}% original style: plain
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\makeatother
\usepackage{makeidx}
\usepackage[titles]{tocloft}
\usepackage{fancyhdr}
\fancyhead{} % clear default layout
\fancyfoot{} % clear default layout
\fancypagestyle{mainmatter}{%
\fancyhead[L]{\sffamily \small \color{darkgray}\MakeUppercase{\bfseries \leftmark}}
\fancyhead[R]{\nouppercase \scshape \small \thepage}
}
\fancypagestyle{frontmatter}{%
\fancyhead[L]{}
\fancyhead[R]{}
\fancyfoot[R]{\thepage}
}
\begin{document}
\frontmatter
\pagestyle{frontmatter}% frontmatter page style
\clearpage
\tableofcontents
\clearpage % with tocloft we need this
\listoffigures
\clearpage % with tocloft we need this
\listoftables
\clearpage
\mainmatter
\pagestyle{mainmatter}
\chapter{A}
\kant
\chapter{B}
\kant
\chapter{C}
\kant
\end{document}
Best Answer
memoir
provides the condition\if@mainmatter
which you can use to condition on whether or not you're in the\mainmatter
section of your document:While I've used
empty
andplain
as the chapter page styles in the mainmatter and frontmatter respectively, you can update this to whatever you want, or even create your own new ones.Also note that
memoir
provides functionality for creating headers/footers, so you don't needfancyhdr
for this.