4

I am writing my thesis and I would like to have the page numbers on the top right corner of each page. And I would like to not have any page numbers on the first page of each chapter. But, I would like to have page numbers on the first page of the special chapters (e.g., acknowledgements, ToC, LoT, LoF etc)...

I am using the following code (mixed and matched from several postings) that gives me indeed page numbers on the top right corner, except from the first page of each chapter (so far so good). But also except from the first page of the special chapters...

Could I somehow define an environment for some of my chapters to have page numbers on their first page (so for ackn, ToC, etc) and then a different environment for the rest of the chapters?

\RequirePackage{fancyhdr} 
\fancypagestyle{phdthesis}{%
\fancyhf{} 
\fancyhead[R]{\thepage} 
}
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \thispagestyle{empty}%
                \global
                \@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother
3

Define a new boolean switch (say, \ifspecialchapter), add a test for this switch to your redefinition of \chapter and set the pagestyle of the chapter's first page accordingly. In the document body, use \specialchaptertrue and \specialchapterfalse as desired.

\documentclass{book}

\usepackage{fancyhdr} 
\fancypagestyle{phdthesis}{%
\fancyhf{} 
\fancyhead[R]{\thepage} 
}
\pagestyle{phdthesis}

\newif\ifspecialchapter
\specialchapterfalse

\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \ifspecialchapter
                  \thispagestyle{phdthesis}%
                \else
                  \thispagestyle{empty}%
                \fi
                \global
                \@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother

\usepackage{lipsum}

\begin{document}

\specialchaptertrue

\tableofcontents

\specialchapterfalse

\chapter{foo}

\lipsum[1-12]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.