18.5 \thepage

If you want to change the appearance of page numbers only in the page headers, for example by adding an ornament, typesetting in small caps, etc., then the fancyhdr package, as mentioned in a previous section, is the best approach.

On the other hand, you may want to change how page numbers are denoted everywhere, including the table of contents and cross-references, as well as the page headers. In this case, you should redefine \thepage, which is the command LaTeX uses for the representation of page numbers.

For example, for the TUGboat journal (https://tug.org/TUGboat), we often circulate draft versions of articles. For this, we change the page numbering to start at 901, but want to print the page numbers with a ‘?’, as in printing ‘?1’ for the first page. This helps avoid people from thinking that the page numbers are final. We want the ‘?’ to appear in the table of contents and cross-references as well as the headers; therefore, we redefine \thepage:

\renewcommand\thepage{%
  \ifnum\value{page}>900
    % In CM, numerals are exactly .5em,
    % so make our `?' have that width too.
    % The \texorpdfstring avoids the hyperref warning:
    %   Token not allowed in a PDF string ... removing `\@ifnextchar' 
    \texorpdfstring{\makebox[.5em][l]{\small ?}}{?}%
    %
    \textsl{\@arabic{\numexpr\value{page}-900\relax}}% assume e-TeX
  \else
    \@arabic{\value{page}}%
  \fi
}

There is another complication. Changing \thepage will probably break makeindex, since it only understands a few kinds of basic counter representations. Thus, a method to extract a standard integer from the document’s special representation has to be provided. Continuing our TUGboat example:

\usepackage{index}
...
\newcommand\specialthepage{\inteval{\value{page}-900}}
\newindex[specialthepage]*{default}{idx}{ind}{Index}

Thanks to Ulrike Fischer for providing this code. There is more discussion at https://tex.stackexchange.com/questions/687258.


Unofficial LaTeX2e reference manual