I'm quite often using references to corresponding sections or text blocks in my thesis.

In consequence, I've already defined a lot of \label{} commands, which I tried to classify with a naming convention like int:txt:WhatIsItAbout for making clear, that it is in the Chapter introduction, refers to a text block and it's about ...

However, all the page references only contain the page where the label is typeset. If I'm referring to a chapter or section which spans more than one page, I'd like to have a page number like S. 23f or S. 23ff

By referencing text blocks it seems even more complicated (as the end of the range is not defined by the occurrence of the next object on the same level): I add a label somewhere, but to define a text range, I would have to define a second label at the end of the text block which would make things even more confusing.

I know about the variorefpackage which can produce such "intelligent" references, but for a page range it also needs 2 labels.
(as described here: Creating a "\label" that, if necessary, spans over several pages)

  • Is there a way to avoid that by e. g. defining an environment which
    • can be referenced and which automatically outputs the start and end page?
    • or which creates 2 labels at its beginning and at its end which are e. g. called LabelnameS and LabelnameE (for start and end) and
      • can be read by either the \vref command with explicitly entering the 2 label names
      • or by a specially defined ref command \rangeref{Labelname} which expands it automatically and creates the page range, if start and end are on different pages.

Remark: However, if really an environment would be used for that, it could cause problems if 2 such environments "intersect" (start of 2nd environment before end of first, but end of second environment after end end of first).

  • How do you handle that?
    • Do you avoid referencing to page ranges or do you always create 2 labels?
    • How do you name your labels to make them short and clear?

1 Answer 1


Since your ranges may intersect, defining an environment is out of the question. It's necessary to mark the start and the end of the range and two labels are to be created; however, LaTeX can do it for you:



You provide only one label, leaving to LaTeX the task of using two of them. Of course you'll have to better define the action of \rangeref. The zref package should be considered for advanced \label-\ref managing.

  • thanks, egreg - I'll need some more days to test and see how it works best and then give you a feedback! Apr 18, 2011 at 10:48
  • Don't you want to be using \pageref{} to retrieve the page number, not \ref{} to retrieve the section number?
    – Geremia
    Oct 4, 2016 at 21:06
  • @Geremia Sure enough!
    – egreg
    Oct 4, 2016 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .