ShareLaTeX guides

LaTeX Basics


Figures and tables

References and Citations


Document structure





Field specific

Class files

L a T e X uses internal counters that provide numbering of pages, sections, tables, figures, etc. This article explains how to access and modify those counters and how to create new ones.



A counter can be easily set to any arbitrary value with \setcounter . See the example below:

This document will present several counting examples, how to reset and 
access them. For instance, if you want to change the numbers in a list.
\item Something.
\item Something else.
\item Another element.
\item The last item in the list.

In this example \setcounter{enumi}{3} sets the value of the item counter in the list to 3. This is the general syntax to manually set the value of any counter. See the reference guide for a complete list of counters.

Open an example in ShareLaTeX

Counter manipulation

Counters in a document can be incremented, reset, accessed and referenced. Let's see an example:

\section{Another section}
This is a dummy section with no purpose whatsoever but to contain text. 
This section has assigned the number \thesection.
\int_{0}^{\infty} \frac{x}{\sin(x)}

In this example, two counters are manipulated:

Prints 2, the value of the counter section at this point. To print the value of a counter just put \the right before the name of the counter.
Increases by 1 the value of the counter equation . Other similar commands are \addtocounter and \refstepcounter , see the reference guide .

Open an example in ShareLaTeX

Creating new counters

The basic syntax to create a new counter is by \newcounter . Below an example that defines a numbered environment called example :

   \textbf{Example~\theexample. #1} \rmfamily}{\medskip}
This document will present...
This is the first example. The counter will be reset at each section.
Below is a second example
And here's another numbered example.
\section{Another section}
This is a dummy section with no purpose whatsoever but to contain text. 
This section has assigned the number \thesection.
\int_{0}^{\infty} \frac{x}{\sin(x)}
This is the first example in this section. 

In this L a T e X snippet the new environment example is defined, this environment has 3 counting-specific commands.

Creates a new counter called example that will be reset every time the section counter is increased. You can put any other counter instead of section or omit the parameter if you don't want your defined counter to be automatically reset.
Increases the counter by 1 and makes it visible for the referencing mechanism.
Prints the current value of the counter example .

For further information on user-defined environments see the article about defining new environments

Open an example in ShareLaTeX

Reference guide

Default counters in L a T e X

Usage Name
For document structure
  • part
  • chapter
  • section
  • subsection
  • subsubsection
  • paragraph
  • subparagraph
  • page
For floats
  • equation
  • figure
  • table
For footnotes
  • footnote
  • mpfootnote
For the enumerate environment
  • enumi
  • enumii
  • enumiii
  • enumiv

Counter manipulation commands

  • Increase the value of the counter by number
  • Incrementation (increase the value of the counter by 1)
  • Incrementation linked with referencing mechanism

It works like \stepcounter , but makes the counter visible to the referencing mechanism ( \ref{label} returns counter value)

  • Set the counter value explicitly
  • Create a new counter (is automatically set to zero)

If you want the NewCounterName counter to be reset to zero every time that another OtherCounterName counter is increased, use:

  • Return the value of the counter. Note, that it is not a formatted string, so it cannot be used in text.
  • Display the value of the counter

for example: \thechapter , \thesection , etc.

Open an example in ShareLaTeX

Further reading

For more information see: