28.03.2013 Views

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

182 Chapter 8. User Cus<strong>to</strong>mizations<br />

8.1.2 User-defined counters<br />

The user may create new counters with the comm<strong>and</strong><br />

\newcounter{counter name}[in counter]<br />

where counter name is the name of the newly established counter. This<br />

may be any combination of letters that is not already the name of an<br />

existing counter. Thus none of the names of the L AT E X counters listed<br />

above may be used as counter name nor any name of a previously defined<br />

user counter.<br />

The optional argument in counter is the name of another counter<br />

that already exists (L AT E X or user defined) <strong>and</strong> has the effect that the newly<br />

defined counter is reset <strong>to</strong> zero whenever in counter is incremented by one<br />

of the comm<strong>and</strong>s \stepcounter or \refstepcounter (see below). For<br />

example, the subsection counter is reset <strong>to</strong> zero whenever the section<br />

counter is incremented.<br />

The \newcounter comm<strong>and</strong> may not appear in any file that is read in<br />

with the \include comm<strong>and</strong> (Section 9.1.2). It is therefore best <strong>to</strong> put all<br />

\newcounter comm<strong>and</strong>s in<strong>to</strong> the preamble.<br />

8.1.3 Changing counter values<br />

Every counter, whether L AT E X or user defined, has an initial value of zero;<br />

this can be altered with the following comm<strong>and</strong>s:<br />

\setcounter{counter}{num}<br />

This comm<strong>and</strong> is self-explana<strong>to</strong>ry: the specified counter is assigned<br />

the integer value num.<br />

\add<strong>to</strong>counter{counter}{num}<br />

With this comm<strong>and</strong>, the value of the counter is increased by the<br />

integer num, which may be positive or negative.<br />

\stepcounter{counter}<br />

The value of the counter is increased by one, <strong>and</strong> at the same<br />

time all its sub-counters (that is, those that have this counter as<br />

their in counter) are reset <strong>to</strong> zero (see above).<br />

\refstepcounter{counter}<br />

This comm<strong>and</strong> has the same effect as \stepcounter but also<br />

makes counter the current counter for the cross-referencing comm<strong>and</strong><br />

\label (see Section 9.2.1).<br />

This last comm<strong>and</strong> may be applied, for example, within the figure<br />

or table environments when the \caption comm<strong>and</strong> is missing <strong>and</strong> yet<br />

there is <strong>to</strong> be a reference in the text <strong>to</strong> the figure or table number using the<br />

\ref comm<strong>and</strong>. Then \refstepcounter{figure} or \refstepcounter<br />

{table} is given within that float environment <strong>to</strong> bring the corresponding

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!