General ⇒ Page, figure and other counters
Page, figure and other counters
I'd like to add pages and figures count to abstract, but found the way only for pages (lastpage package and \pageref{LastPage} in text) and the way to get current object count (standard LaTeX counters).
Could anybody advise, how can I get total figures count at the beginning of my text, or maybe some general way to get total count of different objects (pages, figures, tables, bibliography)?
Thanks in advance
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Page, figure and other counters
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Page, figure and other counters
Thanks for the answer, Thorsten.localghost wrote:Use the totcount package.
As soon as the problem is sorted out, please act according to Section 3 of the Board Rules (last two paragraphs).
Best regards and welcome to the board
Thorsten
totcount works like a charm if figure counter is global. In my case figures are enumerated within chapter (using chngcntr) and totcount return figures count in last section (or I can't tune it to do it in other way). For example, following code showed '0' in PDF document:
Code: Select all
\documentclass[a4paper,12pt]{article}
\usepackage{chngcntr}
\counterwithin{figure}{section}
\usepackage{totcount}
\regtotcounter{figure}
\begin{document}
\total{figure}
\section{section with figures}
\begin{figure}[h]
\centering
\caption{figure}
\label{fig}
\end{figure}
\section{section without figures}
\end{document}
Code: Select all
\documentclass[a4paper,12pt]{article}
\usepackage{chngcntr}
\counterwithin{figure}{section}
\usepackage{totcount}
\regtotcounter{figure}
\newtotcounter{foofigure}
\makeatletter
\renewenvironment{figure}[1][\fps@figure]{
\edef\@tempa{\noexpand\@float{figure}[#1]}
\@tempa
\addtocounter{foofigure}{1}
}{
\end@float
}
\makeatother
\begin{document}
\total{figure}
\total{foofigure}
\section{section with figures}
\begin{figure}[h]
\centering
\caption{figure}
\label{fig}
\end{figure}
\section{section without figures}
\end{document}
Code: Select all
\newtotcounter{foofigure}
\makeatletter
\renewenvironment{figure}[1][\fps@figure]{
\edef\@tempa{\noexpand\@float{figure}[#1]}
\@tempa
\addtocounter{foofigure}{1}
}{
\end@float
}
\makeatother
Code: Select all
\total{foofigure}
Re: Page, figure and other counters
My totalcount package is unfortunately not on CTAN (yet) but could be found here:
http://www.mrunix.de/forums/showpost.ph ... stcount=10
Axel