[Tex/LaTex] Page numbers restart for preliminary pages

fancyhdrheader-footerpage-numbering

I have just started typesetting my PhD thesis. I am using the book class. I have a parent file where I define style, chapter header styling, page numbering, etc., and I include every chapter using \include{}. When compiled I have one single PDF file. However, I have a problem with page numbering on preliminary pages such as Abstract, List of Contents, List of Figures, etc. Page numbers restart on every preliminary page. Here is how my TeX file looks like

%Page number formatting for preliminary pages.
\fancypagestyle{preliminary}{
\fancyhf{}
\fancyfoot[C]{\thepage}
\pagenumbering{roman}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{\pagestyle{preliminary}}}

%Page number formatting for main matter.
\fancypagestyle{mainmatter}{
\fancyhf{}
\fancyfoot[C]{\thepage}
\pagenumbering{arabic}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{\pagestyle{mainmatter}}

\onehalfspacing

\newenvironment{abstract}{\chapter*{Abstract}}{}

\begin{document}

\pagestyle{preliminary}
\setcounter{page}{2}

\begin{abstract}...\end{abstract}

\tableofcontents
\listoffigures
\listoftables

\mainmatter

\pagestyle{mainmatter}
\include{chapter1}

\end{document}

Am I doing something wrong? I have a suspicion that pre-defined page number formatting at the very beginning is causing this but I am not sure. What do you guys think?

Best Answer

You define the two page styles preliminary and mainmatter to be the same, except for the numbering (roman in the former, arabic in the latter). So, for now, the following setup is what you're after:

\documentclass{book}

%... Preamble stuff

% Page style for preliminary pages.
\fancypagestyle{preliminary}{
  \fancyhf{}% Clear header/footer
  \fancyfoot[C]{\thepage}% Footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
}

% Page style for main matter.
\fancypagestyle{mainmatter}{
  \fancyhf{}% Clear header/footer
  \fancyfoot[C]{\thepage}% Footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
}

%...

\begin{document}

\pagestyle{preliminary}\pagenumbering{roman}
\fancypagestyle{plain}{\pagestyle{preliminary}}% Correct plain page style

%... Preliminary stuff

\mainmatter
\pagestyle{mainmatter}\pagenumbering{arabic}
\fancypagestyle{plain}{\pagestyle{mainmatter}}% Correct plain page style

%... Mainmatter stuff

\end{document}

Another common way of copying a page style into another is to use

\makeatletter
\let\ps@plain\ps@preliminary% Copy preliminary page style into plain
\makeatother
Related Question