7

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}

2 Answers 2

7

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:

\documentclass[a4paper,11pt,titlepage,oneside,openany]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{kantlipsum}
% empty style for the first page of every chapter, except in \frontmatter
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \if@mainmatter
                  \thispagestyle{empty}% plain page style in mainmatter
                \else
                  \thispagestyle{plain}% empty page style outside of mainmatter
                \fi%
                \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}

While I've used empty and plain 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 need fancyhdr for this.

3

The titlesec package provides the \assignpagestyle{\chapter}{<style>} command, which can be used just like \pagestyle but changes only the first page of each chapter. It's the same you are doing with \thispagestyle{}, but without explicitly renewing \chapter.

You must log in to answer this question.

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