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 0: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 0: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
6

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}
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.

  • This code gives me "! Undefined control sequence." in \f@nch@ocf ->\ifodd \value {page}\else \inteval {\value {page} / 2}\fi \strut l.16 No page number \newpage Should be 1 \newpage. Humm – Robert Vanden Eynde Jul 25 '18 at 4:21
  • @RobertVandenEynde: Are you including the xfp package like I did? – Werner Jul 25 '18 at 15:22
  • Yep, I copy pasted your code. – Robert Vanden Eynde Jul 25 '18 at 19:07
  • @RobertVandenEynde: What version of the xfp are you using? I'm using one dated 2018-05-12; the latest available. – Werner Jul 25 '18 at 21:22
  • 1
    @RobertVandenEynde: Since it forms part of the LaTeX3 development, it's experimental until further notice. As such, things may change between releases. \inteval seemed to form part of the 2017-09-18 release (announcement). – Werner Jul 26 '18 at 20:36
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).

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.