How to change the page number from even to odd while keeping the page as verso?

4,801

Solution 1

Here is a workaround based on Schweinebake's suggestions, which allows for any offset in the displayed page number vs. the 'physical' page number:

\documentclass[twoside]{article}
\usepackage[showframe]{geometry}

\makeatletter
%usage: 
%\displayedpagenumbering{numbering style}{number to display on current page}
\newcommand{\displayedpagenumbering}[2]{%
  \edef\@tempcntval{\@arabic{\value{page}}}
  \long\@namedef{@#1withoffset}##1{\csname @#1\endcsname{\numexpr ##1 - \@tempcntval + #2\relax}}%
  \pagenumbering{#1withoffset}%
  \setcounter{page}{\@tempcntval}%
}
\makeatother

\begin{document}
This is the first physical page. The displayed page number should be 1.
This should be a right-of-binding page (recto).

\clearpage
\displayedpagenumbering{arabic}{3}
This is the second physical page. The displayed page number should be 3
This page should be a left-of-binding page (verso). Finally, let's see
what a \verb|\pageref| gives us: 
\label{test}
\pageref{test}.

\end{document}

Solution 2

Odd numbered pages should always be right pages!

So you should always use \cleardoublepage before changing page numbering, because it makes no sense to change page numbering on the left side of a double sided print:

\documentclass[twoside]{article}% It's better to tell already the class to use twoside!
\usepackage[showframe]{geometry}
\begin{document}
This is the first page; it should be a right page (recto).
\cleardoublepage
\pagenumbering{arabic}
This is the third page; it should be a right page, because changing page numbering should always be done on right pages!
\end{document}

If you simply wanted to suppress page number at the first page of an article, try:

\documentclass[twoside]{article}% It's better to tell already the class to use twoside!
\usepackage[showframe]{geometry}
\begin{document}
\title{Title}
\author{Me}
\maketitle\thispagestyle{empty}
\begin{abstract}A short abstract of the document.\end{abstract}
Some more text, e.g. a table of contents.
\clearpage
This is the second page; it should be a left page and numbered 2!
\end{document}

Note: You may use \cleardoublepage before \pagenumbering even at oneside documents, because in this case it would have the same result \clearpage would have.

But, if you really, really must have odd pages left and even pages right, you may simply switch the margins (and the margin used for \marginpar):

\documentclass[twoside]{article}% It's better to tell already the class to use twoside!
\usepackage[showframe]{geometry}
\makeatletter
\newcommand*{\flipmargins}{%
  \clearpage
  \setlength{\@tempdima}{\oddsidemargin}%
  \setlength{\oddsidemargin}{\evensidemargin}%
  \setlength{\evensidemargin}{\@tempdima}%
  \if@reversemargin
    \normalmarginpar
  \else
    \reversemarginpar
  \fi
}
\makeatother
\begin{document}
This is the first page; it should be a right page (recto).

\flipmargins
\pagenumbering{roman}
This is the second page; it should be a left page (verso).
\end{document}

Using a page style like headings you may also need to change the page style, e.g., to print the numbers near the outer margin. You may do this, using either scrpage2 or fancyhrd. Here an example using scrpage2:

\documentclass[twoside]{article}% It's better to tell already the class to use twoside!
\usepackage[showframe]{geometry}
\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}

\makeatletter
\newcommand*{\flipmargins}{%
  \clearpage
  \setlength{\@tempdima}{\oddsidemargin}%
  \setlength{\oddsidemargin}{\evensidemargin}%
  \setlength{\evensidemargin}{\@tempdima}%
  \if@reversemargin
    \normalmarginpar
  \else
    \reversemarginpar
  \fi
  \ifdim \evensidemargin>\oddsidemargin
    \ihead{\headmark}%
    \ohead[\pagemark]{\pagemark}%
  \else
    \ihead[\pagemark]{\pagemark}%
    \ohead{\headmark}%
  \fi
}
\makeatother

\begin{document}
\section{Normal pages}
This is the first page; it should be a right page (recto).

\flipmargins
\pagenumbering{roman}
\section{Inverse margin pages}
This is the second page; it should be a left page (verso).
\end{document}

Alternative:

One completely different alternative would be to fake the page number, given by \thepage:

\documentclass[twoside]{article}% It's better to tell already the class to use twoside!
\usepackage[showframe]{geometry}
\makeatletter
\newcommand{\@arabicplusone}[1]{\@arabic{\numexpr #1+1\relax}}
\newcommand{\@romanplusone}[1]{\@roman{\numexpr #1+1\relax}}
\newcommand{\@Romanplusone}[1]{\@Roman{\numexpr #1+1\relax}}
\newcommand{\@alphplusone}[1]{\@alph{\numexpr #1+1\relax}}
\newcommand{\@Alphplusone}[1]{\@Alph{\numexpr #1+1\relax}}
\makeatother

\newcommand*{\pagenumberingplusone}[1]{%
  \pagenumbering{#1plusone}\setcounter{page}{0}%
}

\begin{document}
This is the first page; it should be a right page (recto). See
page~\pageref{test}.

\clearpage\pagenumberingplusone{roman}
This\label{test} is the second page; it should be a left page (verso).
\end{document}

Disadvantage of this suggestion would be, that if a package uses page counter directly for something else but testing odd or even the result may be unexpected. The advantage of this suggestion would be, that pages with odd value of counter page shows not only an even page number but will be handled to be a even=left page by LaTeX and every class or package that uses \c@page or \value{page} for the test (and vica versa).

Solution 3

Well, here's my own idea for "The Right Solution", even though it's not immediately practical.

Counter Separation.

There should be two different counters, each automatically incremented when moving to a new page:

  1. The 'physical' page counter
  2. The 'display' (or 'logical') page counter

Currently, the counter named page (i.e. \c@page) is used for both. LaTeX code should be able to know which physical page its on, in this output file, and also, which number the author wants this page to have - and these need not be the same thing.

I'm guessing this would mean a change to the LaTeX core or at least the default document classes.

Share:
4,801

Related videos on Youtube

einpoklum
Author by

einpoklum

Updated on May 27, 2020

Comments

  • einpoklum
    einpoklum over 3 years

    I'm writing a two-sided document with a binding margin. For certain reasons, I need to change the page number at some point, so what used to be an even-numbered page is now odd-numbered. This makes the geometry package arrange this page as a recto (right-of-margin) rather than a verso (left-of-margin) page - while I need the recto-verso pairs to continue, i.e. I need the page to be a verso.

    MWE follows (the showframe illustrates that the margins are the same rather changing from recto to verso).

    \documentclass{article}
    \usepackage[showframe,twoside]{geometry}
    \begin{document}
    This is the first page. It should be a right-of-binding page (recto).
    \clearpage
    \setcounter{page}{3}
    This is the second page; it should be a left-of-binding page (verso) - but it isn't.
    \clearpage
    This is the third page; it should be a right-of-binding page (recto) - but it isn't.
    \end{document} 
    

    Background: I'm writing my Ph.D. thesis, which is mostly English but has a Hebrew part, which must be numbered differently. Also, Hebrew is an right-to-left language so the pages go in on the other end of the binding, i.e. the Hebrew cover page is a left-of-binding page which goes in 'last' when leafing through the bound booklet left-to-right. I output the Hebrew sheets from first to last, after the last English sheets, then take the whole bunch of Hebrew sheets, and flip them all together and re-place them to get the effect I described. The Hebrew part numbering begins at 1 on a left-of-binding page (not the Hebrew cover page btw.)

    Notes:

    1. Please don't suggest I not do this, or change the page number to something even instead of odd, etc. This is a legitimate need. Other people might want to output a two-sided document with binding margins in which page numbers go 1,1,2,2,3,3,4,4.
    2. A workaround is to 'manually' flip the margins, as suggested by Schweinebacke. But this is not satisfactory as there is also the issue of margin notes and possibly other LaTeX code which might depend on whether the page is a verso or a recto rather than the margin sizes.
    3. A solution should not assume any of the details from my background. Specifically, do not assume that the content on the re-numbered page is in Hebrew, or Right-to-Left etc.
    • einpoklum
      einpoklum almost 12 years
      @Brent.Longborough: At some point in my Ph.D. thesis, I switch to outputting Hebrew pages, which in fact, when printed, need to be be bound in the reverse order, and their numbering has to be reset regardless of this fact, etc. etc. - it's complicated. But forget about all that. The point is that I get two recto's one after the other ! Which is not what should happen, and what I want to fix.
    • Werner
      Werner almost 12 years
      I think geometry prints the frame recto/verso based on whether/not the page counter is odd/even. And, since \pagenumbering{...} resets the counter to 1, it produces the wrong display.
    • einpoklum
      einpoklum almost 12 years
      @Brent.Longborough: suggest we remove our comments so far following my edit.
    • Schweinebacke
      Schweinebacke almost 12 years
      @Werner: It's not geometry that decides wether a page is a left or a right one. It's the LaTeX kernel that decides, that pages with odd page counter use \oddsidemargin and with even page counter use \evensidemargin. Decision for the margin used for margin notes are done in the same kind. And if a package need such a decision it should use \ifodd\c@page too. Unfortunately some broken packages may use \number\thepage instead of \c@page or \value{page}. Because of this my alternative, that makes odd/even numbers show an even/odd number may fail sometimes too.
  • einpoklum
    einpoklum almost 12 years
    I'm sorry, but I don't want to do any of what you suggest. I don't want to have an empty verso page, and I don't want to suppress numbering on a single page - that's just not what I need. I need my verso to stay a verso when I change the page number or numbering style.
  • Schweinebacke
    Schweinebacke almost 12 years
    @EyalRozenberg: I've added two examples to show, how you could do, what I've understand, that you want. Nevertheless I doubt that I really understand it, because I cannot imagine how to print such a document without splitting it into two parts. But if it must be splitted, IMHO making two documents would be the better suggestion.
  • einpoklum
    einpoklum almost 12 years
    As a workaround, this works as long as nothing relies on verso/recto nature of a page. But I want something more robust. For example, margin notes will appear on the wrong side, and so will changebars etc. Now, it so happens that for Hebrew text, the margin note side flipping might not be a bad idea but that's not The Right Thing in general.
  • einpoklum
    einpoklum almost 12 years
    This potentially conflicts with babel, which redefines \@arabic and friends, but I'll check.
  • Schweinebacke
    Schweinebacke almost 12 years
    @EyalRozenberg: I do not redefine \@arabic but simply use it.
  • Schweinebacke
    Schweinebacke almost 12 years
    It would also need a change of several package, that uses counter page either for output or for tests e.g. even/odd tests. Nevertheless I've already shown a kind of such a separation at the second alternative at my answer. There \thepage is the display part of the page counter and \c@page is the physical part used for even/odd tests.
  • einpoklum
    einpoklum almost 12 years
    Using it in certain ways sometimes makes babel complain. Anyway, please have a look at my generalized workaround based on your suggestion (as a separate answer).
  • Douglas De Rizzo Meneghetti
    Douglas De Rizzo Meneghetti over 7 years
    @Schweinebacke Why should odd numbered pages always be right pages? If you, or anyone can answer this, please take a look at this question of mine: tex.stackexchange.com/questions/311515/…