0

I have written a document class in which a titlepage can be created. I suppress the page number on that title page, so my first real page is on the backside of that title page. As such I want it to be page number 1. However using \setcounter{page}{1} in order to decrement the page number globally is not an option as I am using the twosided option of geometry and the binding offset is added based on whether the page number is even or odd. As this offset is exactly how I want it when leaving the page number alone, decrementing it by one obviously messes things up.

Therefore I created a custom macro \myPageNumber that will always print out one less than \thepage and I used that to print page numbers in my footer. That's great but there is one more problem: The page numbers in the TOC are the ones returned by \thepage and as such they are always off by one.

After googling I found Modifying the Page Numbers in the Table of Contents but this involves manually adding the TOC entries for every section etc.
My idea then was basically to change the page-counter temporarily when inserting a new TOC entry and changing it back to normal once that is done. For this my code looks like this:

\documentclass{article}

\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{etoolbox}

\newcommand{\myPageNumber}{\the\numexpr\value{page}-1\relax}%

\cfoot{\myPageNumber}
\chead{}
\rehead{}
\rohead{}

\begin{document}
    \pretocmd{\addcontentsline}{%
        \edef\actualPage{\thepage}%
        \setcounter{page}{\myPageNumber}%
    }{}{}%
    \apptocmd{\addcontentsline}{%
        % <MARKER>
        \setcounter{page}{\actualPage}%
    }{}{}%

    \thispagestyle{empty}
    \vspace*{\fill}
    \begin{center}
        \textbf{\Huge My title page}
    \end{center}

    \vspace{5cm}

    \meaning\addcontentsline

    \vspace*{\fill}

    \newpage

    \tableofcontents

    \hspace{2cm}

    \section{First section}
    \lipsum[3-13]

    \section{Next section}
\end{document}

The thing is that as long as I leave the line under % <MARKER> uncommented, the page number doesn't change at all. This seems weird to me as this only changes the page number after the TOC entry has been written (at least that's my interpretation of what \meaning\addcontentsline spits out.

The question at this point is either how to adapt my code so that the second \setcounter doesn't overwrite the first one before the TOC entry has been written, or how else I could achieve an alternation of the page numbers listed in the TOC (without having to manually adjust every single one of them).

Raven
  • 3,023
  • 1
    aren't your readers going to be confused? It would be more normal to unnumber both pages and make page 1 the first odd side page after the title page. – David Carlisle May 03 '19 at 18:35
  • The thing is that on the page with the TOC there will also be content already. Therefore this should really be the first page – Raven May 03 '19 at 18:39
  • Traditionally recto (right hand) pages have odd numbers and verso (left hand) pages have even numbers. Why do you want to go against centuries of practice and confuse your readers? – Peter Wilson May 04 '19 at 18:05
  • Because for me it makes most sense to make the first page with content page number one. And no reader will be confused by this. Page numbers are for orientation only. And by that I mean that I can look in the TOC and then look for exactly that page number. On which page this number is, doesn't matter. – Raven May 04 '19 at 18:59

0 Answers0