
Есть ли способ, аналогичный тому, что достигается пакетом, lastpage
чтобы получить номер последней главы? Затем я хотел бы использовать эту информацию для проектирования заголовков глав.
решение1
Вариант сtotcount
упаковка:
\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}
А вот вариант без пакетов:
\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}