4

I'm using KOMA-Script scrbook class. And scrpage2 package for headings:

\usepackage{scrpage2}
\clearscrheadfoot
\pagestyle{scrheadings}
\cfoot[\pagemark]{\pagemark}
\chead[]{\headmark}

I want to add an extra pagemark on ofoot. The extra pagemark I need is like this: pp. 181-195, where 181 is the page number where current chapter starts and 195 is where chapter ends. Of course, I need this to change in every chapter.

2 Answers 2

2

I am not aware of a drop-in solution. However, you could do the following:

0) Define \currchapternick at the beginning of your document:

\newcommand{\currchapternick}{}

1) Surround each chapter by the following:

\renewcommand{\currchapternick}{unique-nick-for-chapter}
\label{begin-\currchapternick}
...
\label{end-\currchapternick}

2) Set ofoot as follows:

\ofoot[pp.~\pageref{begin-\currchapternick}--\pageref{end-\currchapternick}]%
      {pp.~\pageref{begin-\currchapternick}--\pageref{end-\currchapternick}}

I have tested the use of macros inside \label and \ref -- works. The code will produce the desired results if the contents of the footer are expanded lazily, which I presume. If not, you could still call \ofoot at the beginning of each chapter, as above.

According to this discussion in the mail archives, there is no such thing as \AtBeginChapter or \AtEndChapter, and hence no way to further automate this unless you delve deeply into TeX internals.

9
  • Note that this problem and its solution also works outside of KOMA and scrpage2.
    – krlmlr
    Sep 23, 2011 at 21:42
  • Thank you! That works fine. Note: \rfoot is not an existing option. I've changed it on my question.
    – Gastón
    Sep 24, 2011 at 11:38
  • ...so I've edited my answer. Do you have to call \ofoot for each chapter, or does it suffice to call it once?
    – krlmlr
    Sep 24, 2011 at 11:41
  • 1
    It suffice to call it once.
    – Gastón
    Sep 24, 2011 at 11:44
  • @user946850: Note that your solution doesn't work perfectly if \chapter (or, more precisely, \cleardoublepage) inserts an empty page before the chapter heading.
    – mhp
    Sep 24, 2011 at 22:58
1

For this task and similar ones, the zref package comes in handy. Based on the abspage and thepage modules provided by this package, you can define a macro \chappagerangelabel as follows:

\documentclass{scrbook}

\usepackage{calc}
\usepackage[abspage, thepage]{zref}
\usepackage{scrpage2}
\usepackage{lipsum}% lorem ipsum placeholder text

\makeatletter

\newcounter{chappagerange}% auxiliary counter

\newcounter{chappointer}% auxiliary counter
\stepcounter{chappointer}% value 1 for first chapter

\newcommand*{\chappagerangelabel}{%
  \zref@label{chappagerange:\the\value{chappointer}}%
  \setcounter{chappagerange}{\zref@extract{chappagerange:\the\value{chappointer}}{abspage}}%
  \edef\thechappagerange{\zthepage{\the\value{chappagerange}}}% first page
  \stepcounter{chappointer}%
  \setcounter{chappagerange}{\zref@extract{chappagerange:\the\value{chappointer}}{abspage}-1}%
  \edef\thechappagerange{pp.~\thechappagerange--\zthepage{\the\value{chappagerange}}}% first page--last page
}

Now, define a macro \pagerangemark modelled after \pagemark:

\DeclareRobustCommand*{\pagerangemark}{%
  {\pnumfont\thechappagerange}%
}

\makeatother

Put \chappagerangelabel at the very beginning of each chapter and immediately after the last chapter and use \pagerangemark in \ofoot:

\begin{document}

\pagestyle{scrheadings}

\clearscrheadfoot
\cfoot[\pagemark]{\pagemark}
\chead[]{\headmark}

\frontmatter

\noindent
Text

\mainmatter

\ofoot[\pagerangemark]{\pagerangemark}

\chapter{A Chapter}
\chappagerangelabel

\lipsum[1-20]

\chapter{Another Chapter}
\chappagerangelabel

\lipsum[21-40]

\backmatter

\chappagerangelabel

\ofoot[]{}

\noindent
Text

\end{document}

Note that this solution does not allow for the case that the last page of the last chapter is also the last page of the whole document. Apart from that, it should work smoothly.

2
  • Now we're halfway towards a new, fully generic sectionranges package, aren't we? :-) Given that you forgot \makeatletter...
    – krlmlr
    Sep 25, 2011 at 0:10
  • Now I see, you call \makeatletter in your preamble. Missed that. Anyway, it would be nice to see a package that encapsulates and automates the above logic.
    – krlmlr
    Sep 25, 2011 at 8:47

You must log in to answer this question.

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