# print number of next page

I know I can use \thepage to print the current page number in my document. But is it possible to print the number of the next page, e.g. for phrases like "continue on page "?

Page numbering (displaying and referencing) should typically be handled using \labels and \refs. Here's an example showing why \thepage is not always accurate:

\documentclass{article}

\usepackage[nopar]{lipsum}

\begin{document}

\lipsum[1-4] \texttt{Page: \thepage}% On page 1, displays as "Page: 1"

\lipsum[5-7] \texttt{Page: \thepage}% On page 2, displays as "Page: 1"

\end{document}


The correct output is displayed when using the \label-\ref system:

\documentclass{article}

\usepackage[nopar]{lipsum}

\begin{document}

\lipsum[1-4] \label{pg:one}\texttt{Page: \pageref{pg:one}}% On page 1, displays as "Page: 1"

\lipsum[5-7] \label{pg:two}\texttt{Page: \pageref{pg:two}}% On page 2, displays as "Page: 2"

\end{document}


The above example works regardless of the representation of the page counter (given by \thepage). For example, one can only perform calculations on \thepage if it expands to a number (via \arabic{page}, typically). It would not be possible to use \thepage within the \frontmatter of a book or report, since then \thepage defaults to \roman{page}.

If you really want to perform calculations on the page number, use the \label-\ref system together with refcount:

\documentclass{article}

\usepackage[nopar]{lipsum}
\usepackage{refcount}

\begin{document}

\lipsum[1-4] \label{pg:one}\texttt{Page: \pageref{pg:one}}% On page 1, displays as "Page: 1"

\lipsum[5-7] \texttt{Page: \number\numexpr\getpagerefnumber{pg:one}+1\relax}% On page 2, displays as "Page: 2"

\end{document}

• I'm using a longtable which expands onto multiple pages. The last row of that longtable should state "continue on page xx" (the next page). I can't label any of the pages, since there's just one longtable environment, and even if I could, I wouldn't want to check where a new page begins, assign them a label each, and manually add a row to my table referring that label. There has to be some kind of automation, isn't it? – LukeLR Feb 1 '17 at 22:32
• @LukeLR: Why not just write "continued on next page"? – Werner Feb 1 '17 at 22:36
• In German, I wouldn't use any equivalent to "continued on next page". At least in my opinion, naming the page number is better german. It's just a detail, but I thought it should be possible. – LukeLR Feb 1 '17 at 22:39
• @LukeLR: The use of this application in longtable is not recommended (see the discussion between myself and the package author in chat). If you're interested in a longtable-specific solution, perhaps consider asking a follow-up question. – Werner Feb 1 '17 at 23:41
• Okay, I'll consider that. Thanks a lot for your efforts! – LukeLR Feb 2 '17 at 3:05

Yes, this is possible, even without the use of any extra packages. Just write a small makro in the preamble of your document like this:

\newcommand{\thenextpage}{
\number\numexpr\thepage+1\relax
}


Then use \thenextpage anywhere in your document to print the number of the next page.

• What happens when \renewcommand{\thepage}{\roman{page}}? – Werner Feb 1 '17 at 18:35
• @Werner \newcommand*{\thenextpage}{\begingroup\addtocounter{page}{1}\thepage\addtocounter{page}{-1}\endgroup} works with Roman page numbers. But, the main problem is usually that the page number is not known in advance because of the asynchronous output routine. Therefore, this will only work in a reliable way, if the location is somewhat known, e.g. at the start of a chapter or right after a \clearpage. – Heiko Oberdiek Feb 1 '17 at 19:14