TeXnik - Tips TeX and LaTeX

Welcome to the TeXnik website (under construction)

Counter - FAQ
 Main page Index UK FAQ Documentation Software CTAN Search CTAN: Statistics Google c.t.t. Google d.c.t.t.
 C Continuing Counting |  Counter-Reset |  I Increment of counters |  N New Counter |  Numbering |  Number of Figures/Pages/Tables/... in a Document |  P Predefined Counter |  R Removing a reset |  Resetting |  S Standard Counter |  Style of counters |  T Total Number of Figures/Tables/... in a Document | Available Packages on CTAN chngcntr dcounter perpage remreset subfloat sublabel

Number of Figures/Pages/Tables/... in a Document
The number of pages in a document is available with the command \ref{TotPages} from package totpages from CTAN. If you want also write the total numbers of figures/tables/... at the beginning of your document, than try the following as an example for tables and documentclass book:
\newcommand*{\OrigChapter}{}
\let\OrigChapter\chapter
\newcounter{abstables}
\renewcommand*{\chapter}{%
\OrigChapter
}
\newcommand*{\AbsTables}{0}
\makeatletter
\AtBeginDocument{%
\AtEndDocument{%
\immediate\write\@mainaux{%
\string\gdef\string\AbsTables{\number\value{abstables}}%
}%
}%
}
\makeatother
In your document you can write at the beginning or anywhere:
This doc has \AbsTables tables and \ref{TotPages} pages.
The above code for the preamble is different, if you
• have document-classes without chapters
• another counter reset

• Continuing Counting
1. If you want your figure to have the same number ("Figure 3") than the forgoing one, just write \addtocounter{figure}{-1} before the caption of the figures except the first.
2. If you want Figure 3a, Figure 3b etc. then put the following lines in the preamble:
\newcounter{parentfigure}
\newenvironment{subfigures}{%
\refstepcounter{figure}%
\protected@edef\theparentfigure{\thefigure}%
\setcounter{parentfigure}{\value{figure}}%
\setcounter{figure}{0}%
\def\thefigure{\theparentfigure\alph{figure}}%
\ignorespaces
}{%
\setcounter{figure}{\value{parentfigure}}%
\ignorespacesafterend
}
Put \begin{subfigures} and \end{subfigures} before/after the figures.

Increment of Counters
• \stepcounter{myCounter} increments myCounter with 1.

New Counter
in latex preamble
• without any automatic reset: \newcounter{myCounter}
• with a reset by chapter: \newcounter{myCounter}[chapter]

in LaTeX the counter is named c@myCounter

Resetting a counter
Removing a given reset
is possible with package remreset
\@removefromreset{myCounter}{section}
Now myCounter is no longer reset when a new section starts.

Automatic reset
A given counter without any automatic reset can be modified with (in LaTeX preamble)
\@addtoreset{myCounter}{section}
Manual reset
\setcounter{mycounter}{0}
myCounter maybe any predefined or new defined (with \newcounter) counter.

Predefined Counter
The following counter are predefined by LaTeX:

 part enumi page chapter enumii equation section enumiii figure subsection enumiv table subsubsection footnote paragraph mpfootnote subparagraph

mpfootnote is the counter for footnotes in minipages. Remember that these counters are only predefined if the environment is also defined! For example: there is no chapter-counter in document-class article, because there is no chapter environment.

Numbering of Counters
Any counter can be printed with the prefix-command \the. A user defined counter myCounter can be printed with \themyCounter. The style can be changed with the \renewcommand. For example:

in LaTeX preamble:

\renewcommand{\thefigure}{\thechapter-\arabic{figure}}
\renewcommand{\thetable}{\arabic{chapter}.\roman{table}.}
\renewcommand{\theequation}{\thechapter-\arabic{equation}}
Now the figures and equations are numbered like 2-5, means "chapter-number". This works only for book classes, because artice classes do not have chapters. The tables are numbered like 2.IV.
• local time: Wed Jan 19 05:38:32 CET 2022 ; file is: 941.740983796296 days old
contact webmaster _at_ TeXnik.de