[Tex/LaTex] Change position of page number after frontmatter

booksfancyhdrheader-footer

My grad school has very specific ideas about the placement of page numbers:

  1. Preliminary pages: lowercase Roman numerals, centered 1/2 inch from the bottom of the page. Begin with the number (ii) on the first page of abstract (no pagination on title page).

  2. Text: Arabic numerals, upper right-hand corner, exactly 1 inch from the right-hand edge of the page and 1/2 inch from the top. Begin with the number one (1) on the first page of text and number consecutively.

How can I achieve this using the book class, and maybe fancyhdr and the like?

Related, but for memoir: How can I change the position of my page number ONLY for one section?

EDIT: The grad school want this one-sided, apparently.

Best Answer

You can do this with geometry, but it will be nearly as complicated. I created a new pagestyle to center the page numbers relative to the page, not the text area. Using symmetrical margins would greatly simplify matters.

The tricky bit is that \topmargin, \oddsidemargin and \evensidemargin are all 1in smaller than the actual margins.

\documentclass{book}
\usepackage{lipsum}% MWE only

\pdfpageheight=\paperheight% geometry usually takes care of this
\pdfpagewidth=\paperwidth

\topmargin=-0.5in % 0.5in-1in
\headheight=\ht\strutbox
% use default \headsep and \footskip
\textheight=\dimexpr \paperheight-1in-\headheight-\headsep-\footskip\relax
% use default \oddsidemargin
\textwidth=\dimexpr \paperwidth-2in-\oddsidemargin\relax
\evensidemargin=0pt
\marginparwidth=\dimexpr 1in-2\marginparsep\relax% probably no \marginpars allowed

\makeatletter
\let\ps@plain=\ps@headings
\def\ps@frontmatter{%
      \let\@oddhead\@empty
      \let\@evenhead\@empty
      \def\@oddfoot{\normalfont\hfil\thepage\hspace{\oddsidemargin}\hfil}%
      \def\@evenfoot{\normalfont\hfil\hspace{\oddsidemargin}\thepage\hfil}}
\makeatother

\begin{document}
\frontmatter
\pagestyle{frontmatter}
\marginpar{This is a long line, but not nearly as long as lipsum.}
\lipsum[1-12]

\mainmatter
\pagestyle{headings}
\chapter{Test}
\lipsum[1-8]
\end{document}