4

I want the page number to be descending and roman. When I change the page number to roman, it doesn't work correctly (uncomment line 9 in MWE and see the output).

MWE:

\documentclass{article}
\textheight1cm
\begin{document}
    1 \newpage 2 \newpage 3
    \newpage
    \setcounter{page}{1}
    \let\oldthepage\thepage
    \renewcommand{\thepage}{\number\numexpr 4-\oldthepage\relax}
%   \renewcommand{\thepage}{\roman{page}}
    iii \newpage ii \newpage i
\end{document}

2 Answers 2

2

You should use the numeric value \value{page} in computations:

\documentclass{article}
\textheight1cm
\begin{document}
    1 \newpage 2 \newpage 3
    \newpage
    \setcounter{page}{1}

    \renewcommand{\thepage}{\romannumeral\numexpr 4-\value{page}\relax}
   
    iii \newpage ii \newpage i
\end{document}
3

You can set the page number display to this to achieve a general, decreasing page number (in roman):

\renewcommand{\thepage}{%
  \romannumeral\numexpr
    \ifcsname @abspage@last\endcsname
      \csname @abspage@last\endcsname% Use \@abspage@last if it exists
    \else
      0% Otherwise use 0
    \fi
    -\value{page}+1%
  \relax}

It uses \@abspage@last (part of the LaTeX kernel since Oct 2020*) to capture the absolute number of pages. Since this value relies on the .aux, you'll have to compile at least twice with any change in the total number of pages.

* You may have to add \usepackage{xparse} to your preamble if you don't have an up-to-date LaTeX.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .