# Calculate amount of figures [duplicate]

Is there way to automatically calculate amount of figures, tables and appendices? I found a way to see what pages have figures(Automatically determine numbers of pages with figures ), but how to calculate the amount.

• The figures counter shoved in caption gives amount of figures in section or chapter or whole document (depend, how you determine \thefigure, which determine caption number). – Zarko Feb 25 '16 at 10:18
• So if want add text like " in the document there is \thefigure(lastfigure) figures" ? – pinq- Feb 25 '16 at 13:07
• Hm, this is not so simple. As I said, depends on how it is defined (if the counter figure is reset at each section or chapter). – Zarko Feb 25 '16 at 13:47
• @Zarko: 'quite' easy (using the 'right' package;-)) – user31729 Feb 25 '16 at 15:44
• @ChristianHupfer, I see your answer (+1). All is simply, if you know haw! – Zarko Feb 25 '16 at 15:46

The number of figures etc. can be retrieved with the totcount package, however, the resetting feature of chapter counters will result in wrong values.

Best is the usage of the xassoccnt and \NewTotalDocumentCounter which combines total counter features with the concept of associated counters, the later are stepped each time a driver counter, say figure is stepped as well, but are not reset. (Manual change is not tracked, of course!)

Using total counters has the advantage that their value is known in advance (after the first run) and can be used right at the start of the document then to do calculation or a specific setup etc.

Two compilation runs are needed, adding/removing a figure/table/chapter etc. will change the number of course and another run is necessary to get the total counter value in line again.

Normally, associated counters should be declared in the preamble already, but the appendix chapters should be counted only, not all chapters, so use \AddAssociatedCounters in place, i.e. right from the position where the feature is needed.

In the example, I assumed appendix chapters, if sections are used, then replace \AddAssociatedCounters{chapter}{appendixchapters} with \AddAssociatedCounters{section}{appendixsections} and change the counter name to appendixsections.

Please note that page is an unreliable counter in conjunction with xassoccnt.

\documentclass{book}

\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalfigures}
\NewTotalDocumentCounter{totaltables}
\NewTotalDocumentCounter{appendixchapters}
\DeclareAssociatedCounters{figure}{totalfigures}
\DeclareAssociatedCounters{table}{totaltables}
\begin{document}

There are \TotalValue{totalfigures} figures in this document

There are \TotalValue{totaltables} tables in this document

There are \TotalValue{appendixchapters} appendix chapters in this document

\chapter{First}

\begin{figure}
\caption{Figure foo \thefigure}
\end{figure}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\chapter{Second}

\begin{figure}
\caption{Figure foo \thefigure}
\end{figure}

\begin{figure}
\caption{Figure foo \thefigure}
\end{figure}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\appendix

\chapter{Foo Appendix}
\chapter{FooBar Appendix}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\begin{table}
\caption{Table foo \thetable}
\end{table}

\end{document}


• Is there possible to end counting before appendix and reset all figure,table, appendix and page numbering to zero without resetting the counter? The counter will not count appendix figures and tables. – pinq- Mar 23 '16 at 13:36
• @pinq-: That's another feature request that was not in your question. – user31729 Mar 23 '16 at 13:51