Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I obtain information about the location of a label relative to other text?

  • Whether the label is on a previous page or the current page (i.e. appears in some previous lines, but on the same page).
  • If the label is on a previous page; how many pages prior? E.g. 1 page before, 5 pages before.

It would be helpful to obtain some value, such as 0 for current page, 1 for the previous page, 2 for two pages previous, as that could be placed into an if-then.

share|improve this question
Would you be able to supply a use case for your conditioning in the form of an example, even if it does not compile? The reason being that two different answers have been given using two different approaches, possibly due to two different questions contained in your post. –  Werner Nov 22 '11 at 4:00

2 Answers 2

This, perhaps is also a partial answer, since it addresses your first bullet.

The varioref package provides \vref and \vpageref that "decorates" a page reference, depending on its location relative to the reference. Here's an example:

enter image description here

\usepackage{varioref}% http://ctan.org/pkg/varioref
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\section{First section} \lipsum[1] \label{sec:first} \lipsum[2-3]
\section{Second section} \lipsum[4-5] \label{sec:second} \lipsum[6-8]
\section{Third section} \lipsum[9-12] \label{sec:third} \lipsum[13]
\section{Fourth section} \label{sec:fourth} \lipsum[14]
\section{Last section} \label{sec:last} \lipsum[15-17] \label{doc:end}
See the reference \vpageref{sec:last} or \vpageref{sec:second}.
share|improve this answer

Here is a partial solution: use \pageref to get the page number of where the \label was defined.

enter image description here



\newcommand{\ShowRef}[1]{Section #1 is on Page~\pageref{#1}\par}%




share|improve this answer
@cmhughes: It gives a solution for the second bullet point. –  Caramdir Nov 22 '11 at 3:45
It does however have problems when TeX decides to move the reference to a new page while typesetting (as the pagecounter will be incorrect). –  Caramdir Nov 22 '11 at 3:46
I wonder whether zref's \zpageref is required here...? –  Werner Nov 22 '11 at 3:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.