GeneralPage, figure and other counters

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
gim
Posts: 2
Joined: Wed Jun 02, 2010 9:12 am

Page, figure and other counters

Post by gim »

Hi!

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
Last edited by gim on Wed Jun 02, 2010 4:12 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Page, figure and other counters

Post by localghost »

Use the totcount package.


Best regards and welcome to the board
Thorsten
gim
Posts: 2
Joined: Wed Jun 02, 2010 9:12 am

Page, figure and other counters

Post by gim »

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
Thanks for the answer, 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

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
But if I comment 'counterwithin' line, it shows '1'. So I decided to redefine figure environment to increment my own counter and not mess with standard. I've googled a little and found a way to redefine figure. So I get following modification of previous code that enumerate figures within section and count them in right way (hope it work not only in my case):

Code: Select all

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
In short to solve my problem it was needed to register new total counter and redefine figure environment to increment it (this code I've placed in preheader.tex with 'usepackage' and other similar stuff):

Code: Select all

Code, edit and compile here:
\newtotcounter{foofigure}
\makeatletter
\renewenvironment{figure}[1][\fps@figure]{
\edef\@tempa{\noexpand\@float{figure}[#1]}
\@tempa
\addtocounter{foofigure}{1}
}{
\end@float
}
\makeatother
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Then counter value could be inserted in standard way:

Code: Select all

\total{foofigure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Re: Page, figure and other counters

Post by sommerfee »

Another option would be using \usepackage[figure]{totalcount} and \totalfigures.

My totalcount package is unfortunately not on CTAN (yet) but could be found here:

http://www.mrunix.de/forums/showpost.ph ... stcount=10

Axel
Post Reply