2

This is a follow-up to Cross Referencing Multiple Pages with the Pageref and Label Commands

Consider the code

\documentclass[12pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{cleveref}

% To print a dash between the page numbers in the range.
\crefname{page}{p.}{pp.}
\newcommand*{\crefrangeconjunction}{--}

\begin{document}
\thispagestyle{empty}

See \cpageref{R1,R2,R3,R4}.

\newpage
Some words.
\label{R1}
\newpage
Some words.
\label{R2}
\newpage
Some words.
\label{R3}
\newpage
Some words.
\label{R4}
\end{document}

which produces

enter image description here

Though the output is exactly what I want, it seems that the labeling task might become quite laborious if, say, a hundred consecutive cross-referenced pages were involved.

QUESTION: How may I make the labeling process more efficient; that is, might there be a way, say, to reference the first and last pages in a consecutive string of pages so that LateX produces the desired output, in this case, See pp. 2--5 without having to label every referenced page?

Thank you.

1
  • @Teepeemm No; it's not clear to me how such is to be incorporated; does such obviate the need for reference labels; if so how? Perhaps you might post a working answer that clearly shows the application of these commands that you suggest. Jun 3 at 20:23

2 Answers 2

4

You asked:

might there be a way, say, to reference the first and last pages in a consecutive string of pages so that LateX produces the desired output, in this case, "See pp. 2--5" without having to label every referenced page?

cleveref defines \cpagerefrange, so that

See \cpagerefrange{R1}{R4}.

gives the output you want.

(Note also that your original example needs the patch from the linked answer in order to have the output you show. \cpagerefrange doesn't need the patch.)

0
1

I tried to follow the above answer but got a little confused at first. When I figured it out, I thought it might be helpful to post a full working example.

\documentclass[12pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{cleveref} %defines \cpagerefrange

% Print a dash between the page numbers in the range:
\crefname{page}{p.}{pp.}
\newcommand*{\crefrangeconjunction}{--}

\begin{document}
\thispagestyle{empty}

See \cpagerefrange{R1}{R4}

\newpage
Some words.
\label{R1}

\newpage
Some words.

\newpage
Some words.

\newpage
Some words.
\label{R4}
\end{document}

Giving the desired output:

enter image description here

You must log in to answer this question.

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