5

I want to put negative number page before the main page of a book document class.

So, I will have something like page -4, -3, -2, -1, 0 (this is the first main page), 1, 2…

I can put on the top of the document environment \setcounter{page}{-<number>} but I have to know how many pages is before the \mainmatter to put it as a <number> variable. So how can I get this value?

  • 2
    You'd need two passes for that. – jub0bs Sep 4 '14 at 19:56
  • Are you aiming for a prize for the most unexpected and unusual page numbering look? – Mico Sep 4 '14 at 21:03
  • Yes Judobs, I know that. Mico, no I was just want to do that for a long time :D – fauve Sep 4 '14 at 23:35
6

The following example uses package zref, in especially zref-abspage, which provides a counter for the absolute page number. \mainmatter writes a reference mainmatter with property abspage, the absolute page number, into the .aux file. In the next run, the page number is set at the beginning in \frontmatter to the negative number:

\documentclass{book}

\usepackage{zref-abspage}

\makeatletter
% Add label to \mainmatter for the absolute page number
\g@addto@macro\mainmatter{%
  \zref@labelbyprops{mainmatter}{abspage}%
}
\g@addto@macro\frontmatter{%
  % Overwrite \pagenumbering{roman} of the original \frontmatter
  \pagenumbering{arabic}%
  % Set the page number to the number of pages in the frontmatter
  % with reverted sign.
  \setcounter{page}{-\zref@extractdefault{mainmatter}{abspage}{0}}%
  % The label is already on page n + 1, the first page of the main matter.
  \stepcounter{page}%
  % Also page number 0 is available:
  \stepcounter{page}%
  % Ensure, that the first page is odd-numbered.
  \ifodd\value{page}%
  \else
    \addtocounter{page}{-1}%
  \fi
  \zref@refused{mainmatter}%
}
\makeatother

\begin{document}
\frontmatter
\tableofcontents
\chapter{Introduction}
\mainmatter
\chapter{Main chapter}
\end{document}

Result:

  • Page -3: Contents
  • Page -2: Empty page because of \cleardoublepage of the following \chapter
  • Page -1: Chapter "Introduction"
  • Page 0: Empty page because of \cleardobulepage of the following \mainmatter
  • Page 1: Chapter "Main chapter", the first page in main matter
  • It’s good but I want to have the 0 page number on the page “Main chapter”, the first page in main matter. For this, have I to set \setcounter{page}{-\zref@extractdefault{mainmatter}{abspage}{-1}}? – fauve Sep 5 '14 at 0:22
  • @fauve However 0 is an even number, but chapters usually start with an odd page number on the right side. – Heiko Oberdiek Sep 5 '14 at 5:19

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.