You can use auxiliary counters for figures and tables and patch \chapter
(using the etoolbox
package, for example) to add the value \value{figure}
(resp. \value{table}) to the respective auxiliary counter; a similar procedure can be applied for tables; then, at the end of the document this operation is once again performed and the result is written to the .aux
file in two macros that hold the total values:
\documentclass{report}
\usepackage{etoolbox}
\newcounter{totfigures}
\newcounter{tottables}
\providecommand\totfig{}
\providecommand\tottab{}
\makeatletter
\AtEndDocument{%
\addtocounter{totfigures}{\value{figure}}%
\addtocounter{tottables}{\value{table}}%
\immediate\write\@mainaux{%
\string\gdef\string\totfig{\number\value{totfigures}}%
\string\gdef\string\tottab{\number\value{tottables}}%
}%
}
\makeatother
\pretocmd{\chapter}{\addtocounter{totfigures}{\value{figure}}\setcounter{figure}{0}}{}{}
\pretocmd{\chapter}{\addtocounter{tottables}{\value{table}}\setcounter{table}{0}}{}{}
\begin{document}
\chapter{Test Chapter One}
There are \totfig\ figures and \tottab\ tables in this document.
\begin{figure}FA\caption{test FA}\end{figure}
\begin{table}TA\caption{test TA}\end{table}
\begin{figure}FB\caption{test FB}\end{figure}
\chapter{Test Chapter Two}
\begin{figure}FC\caption{test FC}\end{figure}
\begin{figure}FD\caption{test FD}\end{figure}
\begin{table}TB\caption{test TB}\end{table}
\begin{figure}FE\caption{test FE}\end{figure}
\chapter{Test Chapter Three}
\begin{table}TC\caption{test TC}\end{table}
\begin{figure}FF\caption{test FF}\end{figure}
\begin{table}TD\caption{test TD}\end{table}
\end{document}
You need to run at least twice the code.
After testing, I noticed that, for some reason, if some chapter does not contain any figures, the counting is wrong. By appending \setcounter{figure}{0}
to the \pretocmd
code, I get the correct results. My guess is that the figure counter holds the value of the previous chapter, when no figures have been defined in the current chapter. I may be wrong though. In any case, resetting the counter when starting the chapter will not produce any unexpected results.