Next: , Previous: , Up: Definitions   [Contents][Index]


12.5 \newcounter: Allocating a counter

Synopsis, one of:

\newcounter{countername}
\newcounter{countername}[supercounter]

Globally defines a new counter named countername and initialize it to zero (see Counters).

The name countername must consist of letters only. It does not begin with a backslash. This name must not already be in use by another counter.

When you use the optional argument [supercounter] then the counter countername will be reset to zero whenever supercounter is incremented. For example, ordinarily subsection is numbered within section so that any time you increment section, either with \stepcounter (see \stepcounter) or \refstepcounter (see \refstepcounter), then LaTeX will reset subsection to zero.

This example

\newcounter{asuper}  \setcounter{asuper}{1}
\newcounter{asub}[asuper] \setcounter{asub}{3}   % Note `asuper'
The value of asuper is \arabic{asuper} and of asub is \arabic{asub}.
\stepcounter{asuper}
Now asuper is \arabic{asuper} while asub is \arabic{asub}.

produces ‘The value of asuper is 1 and that of asub is 3’ and ‘Now asuper is 2 while asub is 0’.

If the counter already exists, for instance by entering asuper twice, then you get something like ‘LaTeX Error: Command \c@asuper already defined. Or name \end... illegal, see p.192 of the manual.’.

If you use the optional argument then the super counter must already exist. Entering \newcounter{jh}[lh] when lh is not a defined counter will get you ‘LaTeX Error: No counter 'lh' defined.


Unofficial LaTeX2e reference manual