3

Is there some counter that holds the number of \chapter that are in a \part? Or do I need to define and run my own counter?

1 Answer 1

3

No such counter exists, as far as I know. However, a running count of the number of chapters within a part can easily be done (see below).

Accessing the total number of chapters within a part at any point of the document (e.g. at the very beginning of a the part in question) is a little trickier. That would probably require running a first pass, retrieving information on the number of chapters from the auxiliary files, processing it, and running a second pass. I don't know how to do that.

\documentclass{book}

\newcounter{totalch}

\let\oldpart\part
\renewcommand{\part}{\setcounter{totalch}{0}\oldpart}

\let\oldchapter\chapter
\renewcommand{\chapter}{\addtocounter{totalch}{1}\oldchapter}

\begin{document}

\part{foo}
\chapter{one}
\chapter{two}
\chapter{three}
\thetotalch    %returns 3, here

\part{bar}
\chapter{four}
\chapter{five}
\thetotalch    %returns 2, here

\end{document}
0

You must log in to answer this question.

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