I have an article of nine pages which include three kinds of page number styles – Roman
, arabic
and Alph
. The layout of the pages and their logical numbers are: I II 1 2 3 4 A B C
.
I want to get the physical (absolute) page number of a given page from a macro (or counter). For example, it should be 7
for the page with logical number A
, and 5
for the page with logical number 3
.
I tried with the LaTeX macro \ReadonlyShipoutCounter
, but this macro did not give the right number.
Anyone can help me? Preferably without using other packages.
Example:
\documentclass{article}
\usepackage{geometry,fancyhdr}
\geometry{showframe}
\pagestyle{fancy}
% My Try: (not succeessful)
\newcommand\abspagenumber{\the\ReadonlyShipoutCounter}
% My Intent:
\newcommand\abspage{...}%output the absolute page number of a certain page in article
\rhead{\thepage}
\chead{Currrent Physical Page Number is: \abspagenumber}
%\lhead{Currrent Physical Page Number is: \abspage}
\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
sencond page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
fourth page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
fifth page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
sixth page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
\pagenumbering{Alph}
seventh page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\clearpage
eighth page\par current absolute page number is: \abspagenumber\par
% The absolute page number of this page is: \abspage.
\clearpage
nineth page\par current absolute page number is: \abspagenumber
% The absolute page number of this page is: \abspage.
\end{document}
Edit:
Base on the solution given by Ulrike Fischer I have another request:
How can I make \abspagenumber
work in a watermark?
\documentclass{article}
\usepackage{geometry,fancyhdr,eso-pic}
\geometry{showframe}
\pagestyle{fancy}
\newcommand\abspagenumber{\inteval{\ReadonlyShipoutCounter+1}}
\rhead{\thepage}
\chead{Currrent Physical Page Number is: \abspagenumber}
\begin{document}
\pagenumbering{Roman}
first page\par current absolute page number is: \abspagenumber
\AddToShipoutPictureBG{\AtPageCenter{\abspagenumber}}
\clearpage
sencond page\par current absolute page number is: \abspagenumber
\clearpage
\pagenumbering{arabic}
third page\par current absolute page number is: \abspagenumber
\clearpage
fourth page\par current absolute page number is: \abspagenumber
\clearpage
fifth page\par current absolute page number is: \abspagenumber
\AddToShipoutPictureBG{\AtPageCenter{\abspagenumber}}
\clearpage
sixth page\par current absolute page number is: \abspagenumber
\end{document}
\Hy@pagecounter
(all counters are counts, but not all counts are counters).\the\Hy@pagecounter
in each page of my article, and they all typeset 0. As I don't fine related description about the count\Hy@pagecounter
in the manuel, would you provide with an example or answer to illustrate how to use it?