5

I need to put page numbers only on even pages:

  • Page 1, no page number.
  • Page 2, number 1.
  • Page 3, no page number.
  • Page 4, number 2.
  • Page 5, no page number.
  • Page 6, number 3.

I guess I need to mess a bit with the page numbering system like a \renewcommand{\thepage} that would divide the page by two or check if it's even?

\documentclass{article}

\begin{document}
No page number \newpage Should be 1 \newpage
No page number \newpage Should be 2 \newpage
No page number \newpage Should be 3 \newpage
\end{document}
  • What have you got so far? Post code for a minimal document with page numbers on all pages and somebody will show you how to make them show only on the even ones. – cfr Jul 25 '18 at 00:15
  • I thought of writing a code but I just want a toy example, meaning I only have like \documentclass{article} \begin{document} ... \end{document}. This basic code already displays the pages at the bottom of the page. – Robert Vanden Eynde Jul 25 '18 at 00:54
  • Suppose you have a \section that starts on the third physical page (the page without number that comes right before the page numbered “2”): what page number should show up in the ToC entry for this section? – GuM Jul 25 '18 at 11:16

3 Answers3

7

Here's a solution that uses the fancyhdr package to redefine the plain page style. The logic is simple. The page number is not printed if it's odd. If it's even, the page number is divided by two and then printed.

Note that this doesn't change actual page number, so cross references and table of contents will be wrong if you use them. But I'm not sure how to avoid this if you are not numbering every page.

\documentclass{article}
\usepackage{lipsum}
\usepackage{fancyhdr}
\makeatletter
\newcount\halfpage
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[C]{%
    \ifodd\c@page
    \else
      \halfpage=\c@page
      \divide\halfpage by 2
      \@arabic{\halfpage}%
    \fi}%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}}
\makeatother
\pagestyle{plain}
\begin{document}
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
David Purton
  • 25,884
4

You can perform a calculation for the even pages and divide the page number by 2:

\documentclass{article}

\usepackage{fancyhdr,xfp}

\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\fancyfoot[C]{%
  \ifodd\value{page}\else
    \inteval{\value{page} / 2}% Divide even page number by 2
  \fi
}
\renewcommand{\headrulewidth}{0pt}% Remove header rule

\begin{document}

No page number \newpage Should be 1 \newpage
No page number \newpage Should be 2 \newpage
No page number \newpage Should be 3 \newpage

\end{document}

Note though that \thepage (the original page number) will be stored for every \label, as well as in the ToC. If you want to be able to use the new page number in these as well, more work needs to be done.

Werner
  • 603,163
0

Here is a solution where thepage is redefined (no need for a custom header). This even works with hyperref and shows the desired page number in the PDF bookmarks.

\documentclass{article}

\usepackage{hyperref}%% optional
\providecommand{\texorpdfstring}[2]{#1} %% makes hyperref package optional

%% Format that you want to see on the pages and in references:
\def\pageformatTexEven{\arabic{HalfPage}}
\def\pageformatTexOdd{}%% Note: this will also not show a page number in references and toc
%% Will be shown in pdf bookmarks:
\def\pageformatInternalEven{\arabic{HalfPage}}
%\def\pageformatInternalOdd{\arabic{HalfPage}b}
\def\pageformatInternalOdd{\arabic{HalfPage}}

%% Manually set the page number on every page:
\usepackage{everypage}
\makeatletter
\newcount\halfpage
\newcounter{HalfPage}
\AddEverypageHook{%
    \halfpage=\c@page%
    \divide\halfpage by 2%
    \setcounter{HalfPage}{\halfpage}%
    \ifodd\c@page%
        \global\def\thepageformat{%
            \texorpdfstring{\pageformatTexOdd}{\pageformatInternalOdd}%
        }%
    \else%
        \global\def\thepageformat{%
            \texorpdfstring{\pageformatTexEven}{\pageformatInternalEven}%
        }%
    \fi%
}
\makeatother
\renewcommand*{\thepage}{\thepageformat}


\begin{document}
    %% Just for better visualization:
    \renewcommand*{\thepage}{\Huge\thepageformat}

    {\Huge \tableofcontents}
    \section{A} No page number \newpage \section{B} Should be 1 \newpage
    \section{C} No page number \newpage \section{D} Should be 2 \newpage
    \section{E} No page number \newpage \section{F} Should be 3 \newpage
\end{document}

A package like fancyhdr is only needed to suppress the page number if \pageformatTexOdd is defined to show a page number (for table of contents and references).

Scz
  • 1,633