I would like to use \pageref's for a range of pages ie. at one point in my file I have something along the lines of

See pages \pageref{ref1}--\pageref{ref1_end}.

Where ref1 points to some section, and I would like ref1_end to point to the end of that section:

\section{section 1}\label{ref1}
a lot of text.\label{ref1_end} % label does not work: Reference `ref1_end' on page X undefined on input line Y.

\section{section 2}\label{ref2}
more text \label{ref2_end}

Using \pageref{ref1}--\pageref{ref1_end} would be wrong if there is a pagebreak between the two sections.

How can I add a label to the end of the text. Is there some way of doing this using some 0-size environment or phantom section?

Note: this question should be quite related to this and this, but differs in that I want to know what I can attach the label to without the output text and spacing having to look any different.

1 Answer 1


You need to mark the end of the section with a label. I adopted your scheme of adding _end for the final label.





See \pagerefrange{ref1} and \pagerefrange{ref2}.

\section{A long section}\label{ref1}


\section{A short section}\label{ref2}



The macro compares the two page references, if they're equal “page n” is issued, otherwise “pages m–n”.

enter image description here

  • This looks really nice. You were right in that I could add a label straight in the text. It seems I had a typo.
    – M.T
    Commented Mar 15, 2020 at 17:33
  • Great code, but It doesn't work for roman numerals. Could you adapt it to this case?
    – yannis
    Commented Dec 4, 2021 at 15:50

You must log in to answer this question.

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