3

Is there a way similar to what is achieved by the lastpage package to get the Last Chapter number? I would then like to use this information to design chapter headings.

1
  • 1
    The package totcount should help
    – egreg
    Commented Apr 6, 2013 at 15:41

1 Answer 1

7

An option with the totcount package:

\documentclass{book}
\usepackage{totcount}

\regtotcounter{chapter}

\begin{document}

This document has~\total{chapter} chapters.
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}

\end{document}

And here's an option without packages:

\documentclass{book}

\newcounter{totchap}

\providecommand\totchap{} 

\makeatletter
\AtEndDocument{%
  \setcounter{totchap}{\value{chapter}}%
  \immediate\write\@mainaux{%
    \string\gdef\string\totchap{\number\value{totchap}}%
  }%
}
\makeatother
\begin{document}

This document has~\totchap\ chapters.
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}

\end{document}

You must log in to answer this question.

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