2

Possible Duplicate:
How to use \pageref{foo} as a number?

i'd like to store the current page number into a variable and reuse it later:

% Roman numbers list of contents list of figures

variable lastpagenumber = this.page.currentnumber

% Arabic numbers contents

% Literature & Appendix pagenumbering: Roman

start with page (lastpagenumber)

if you could show me the defining, setting and reusing of the variable that'd be great.

ndrizza
  • 29

1 Answers1

4

You could use \label on the page in question and \pageref where you want to later reference it.

MWE:

\documentclass{article}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}

\lipsum[1-5]

\label{I want to remember this first page}

\lipsum[6-20]

I've remembered the page \pageref{I want to remember this first page}

\end{document}

Do note that you must compile your document twice to get the page references correct.

Here's an example which let's you put material in the header and footer:

\documentclass{article}
\usepackage{fancyhdr}\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}\renewcommand{\footrulewidth}{0.4pt}
\usepackage{lipsum}
\begin{document}

\lipsum[1-5]

\label{I want to remember this first page}

\lipsum[6-20]

I've remembered the question \pageref{I want to remember this first page}

Check out the bottom of the page:
\cfoot{My reference to the first page\pageref{I want to remember this first page}}

\end{document}

I've called the package fancyhdr to accomplish this, but make sure you don't call \pagestyle{empty} as I did in the first example or you won't see anything.

A.Ellett
  • 50,533
  • ooh you beat me by less than a second, I'll delete my answer which was the same, so +1:-) – David Carlisle Dec 12 '12 at 23:25
  • doesn't work. just prints the page number into the text area instead of the footer area. any method to convert the string to int? – ndrizza Dec 12 '12 at 23:35
  • Give a MWE so we can better see what you're trying to do and better understand the issue you're facing – A.Ellett Dec 12 '12 at 23:40
  • Make sure you get rid of the\pagestyle{empty}. That might be your problem if you too literally copied my example. Sorry (my bad) I should have removed that line from my MWE – A.Ellett Dec 12 '12 at 23:43
  • that does not support automatic incrementing of numbers. isn't there any way to convert the string (returned by pageref) to an integer? – ndrizza Dec 13 '12 at 01:03
  • Have you tried: \setcounter{testcnt}{\pageref{I want to remember this first page}} – A.Ellett Dec 13 '12 at 01:13
  • @ndrizza: consider also \getpagerefnumber from the refcount package instead of \pageref – cyberSingularity Dec 13 '12 at 01:33
  • not working either... i'll go for the manual solution. – ndrizza Dec 13 '12 at 20:26
  • So ... this is 1/2 way working for me. I made a unique label on the page that I want to remember, I later refer to the page ... and the actual page number is correctly printed ... but, it somehow generates a LINK to the starting page of the CHAPTER that contains the page ... which is several pages off. Any ideas of what to correct ? – RichWalt May 01 '22 at 22:31
  • @RichWalt It's hard to say without seeing your code. Trim you document down to a manageable size such that the error is still duplicated and then post it as a question here. – A.Ellett May 01 '22 at 22:52
  • @A.Ellett ... Yeah ... that's probably the only way to solve this issue. Done: posted at: https://tex.stackexchange.com/questions/642782/. Thanks if you're able to take a look at this. – RichWalt May 02 '22 at 15:52