# Page numbering range with first - last page [closed]

I've been trying to output a page range, including the first and last page numbers of the chapter (e.g. "p. 20 - 39"). I've been using the \pageref{LastPage} command for the last page of the chapter, but can't find a way to output the first page (ideally a command such as \pageref{FirstPage}). Any help would be appreciated.

## closed as unclear what you're asking by egreg, Guido, Mensch, Svend Tveskæg, user31729 Oct 8 '14 at 11:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 8 '14 at 18:12
• We usually use two \label commands related to the chapter number. Please post an MWE and we can try an experiment or two to get it work in your example. – Malipivo Aug 9 '14 at 5:58
• you seem to think that lastpage gives you the last page of the chapter ... it doesn’t – it gives you the last page of the whole document. (feel free to ignore if i’ve misunderstood what you said.) – wasteofspace Aug 9 '14 at 7:54

As was said in the comments LastPage gives the last page of the document and thus may not be very helpful for what you're trying to achieve. I suggest defining a label at the beginning of each chapter and then using those labels to get the pages between them. Consider the following:

\documentclass{scrbook}

\usepackage{lastpage}
\newcounter{rangeendpage}
\newcounter{rangepages}
\newcommand{\setpagecounters}[2]{%
\setcounter{rangeendpage}{\pageref{#2}}
\setcounter{rangepages}{\pageref{#2}}
\makeatletter
\if\therangepages0%
\setcounter{rangeendpage}{\pageref{#2}}
\setcounter{rangepages}{1}
\fi
\makeatother
}

\usepackage{blindtext}
\begin{document}
\chapter{Chapter 1}\label{ch1}
\setpagecounters{ch1}{ch2}
This chapter contains pages \pageref{ch1} to \arabic{rangeendpage}, which is \arabic{rangepages} in total.

\Blindtext
\Blindtext

\chapter{Chapter 2}\label{ch2}
\setpagecounters{ch2}{ch3}
This chapter contains pages \pageref{ch2} to \arabic{rangeendpage}, which is \arabic{rangepages} in total.
\blindtext

\chapter{Chapter 3}\label{ch3}
\setpagecounters{ch3}{LastPage}
This chapter is the last and contains pages \pageref{ch3} to \arabic{rangeendpage}, which is \arabic{rangepages} in total.

\end{document}


which will produce output like this:

The example uses the LastPage for the very last chapter. It also takes care of the case where a chapter is only one page - see Chapter 3. Blank pages before the start of a new chapter are counted towards the previous chapter - see Chapter 1.

• oh, just noticed something similar was already here – greyshade Aug 9 '14 at 8:57
• This seems to work. Many thanks for your help! – user60426 Aug 10 '14 at 9:04