counters

StartLaTeX faqLaTeX topicsfont sizearrowsminipageitalicsboldtext colormatrixfontslistingstables

1 LaTeX Counter

Within LaTeX many elements are counted automatically. The most obvious example of such a counter is the page number. This number already appears on every page of the standard document classes without any intervention.

1.1 What is counted

But besides the page number some other elements are counted as well.

The names of the counters are very close to the commands and environments counted by this counter.

tables of ...

There are commands or environments for the table of contents as well as the table of figures and tables that have a counter.

There are seven counters for the table of contents: part for volumes, chapter for chapters (Note: Since there is no command chapter within the article class, there is also no counter chapter in this document class.), section for sections, subsection for sub-sections, subsubsection for sub-subsections, paragraph for paragraphs and subparagraph for sub-sections.

for sections, subsubsection for sub-subsections, paragraph for paragraphs and subparagraph for sub-sections.

for sub-sections.

The counters in the directory of figures and tables are figure respectively table.

Pages
The counter for the pages is page.
Equations
The counter for the equations is equation.

Footnotes

There are two counters for the footnotes. First the counter footnote which is intended for footnotes within normal pages and second the counter mpfootnote which is intended for counting footnotes within a minipage environment.

numbered listing

Within the enumerate environment four counters exist for the four levels, enumi for the first level, enumii for the second level, enumiii for the third level and enumiv for the fourth level.

1.2 Counter symbols

These counters do not all count with Arabic numerals. For example, footnote counts with Arabic numerals, while mpfootnote counts with small Latin characters. This prevents the order of the footnotes from getting mixed up as a result of a minipage.

The following six different symbols are available for counting. The expression name stands here as an example for the possible name of a counter. Only whole numbers can be counted. In addition, the range of numbers, which means the range of numbers that can be displayed, is not the same for all counting symbols.

roman{name}

For roman, the value of the counter is output in the form of small Roman numeric symbols. Whereby the symbols have their known value, i.e. i = 1, v = 5, x = 10, l = 50, c = 100, d = 500 and m = 1000, the symbols for larger numbers are not available, so that the number range from 1 to 5000 can be represented, but a representation of larger values leads to comparatively long numbers. A further limitation of these symbols is that there is no sign for zero and no negative values can be displayed. To be more precise, these values are output as empty strings. The packages romannum and romanbar, which cover both the zero and negative numbers, provide a remedy here.


Roman{name}

The number symbols are displayed with capital letters at Roman, otherwise it behaves like roman.

arabic{name}

The range of numbers from arabic includes the integers from 2-31 to 231-1.

alph{name}

The number range from alph covers the whole numbers from 1 to 26 and the output is in the form of small Latin letters a to z. Again, there is no zero and no negative values.

Alph{name}

For Alph large Latin letters from A to Z are used to represent numbers from 1 to 26, otherwise like alph.

fnsymbol{name}
fnsymbol provides a total of nine footnote symbols for numbers from 1 to 9.
footnote symbols
1
2
3
4?
5?
6||
7★★
8††
9‡‡

Hint

If a value is to be displayed that is larger than the number range of the count symbol, the following message is displayed:

! LaTeX Error: Counter too large. 

For example, if a counter reading of 10 is to be output as a footnote symbol or the value 30 is to be displayed with small (large) Latin letters. In this case, the symbol for counting should be changed.

2 Commands around counting

The commands can be roughly divided into two areas. The creation of new counters and the editing of existing counters.

2.1 Create new counters

New counters can be created relatively easily with the command \newcounter{name}. A name that has not yet been assigned must be used.

\newcounter{mycounter}
The newly created counter mycounter has the value zero.

2.1.1 Counter with reset point

In the event that the new counter is to be reset to zero depending on a second counter, for example because a certain object is to be counted section by section, the second second counter is specified when the new counter is created. In short, when is the (newly created) counter to be reset to zero?

\newcounter{mycounter}[section]
Now the counter mycounter is always reset to zero if the counter section increases.

This effect does not only exist with self-created counters, but also with already existing counters. The usepackage chngcntr offers the possibility to cancel existing reset points or to insert new ones.

2.1.2 Assign a value to counters

The command \setcounter{name}{new value} assigns a new value to the counter name.

\setcounter{mycounter}{17}
Now the counter mycounter has the value 17.

2.2 Commands for existing counters

add / subtract values

With the command \addtocounter{name}{value} a value can be added to a counter or in case the value is negative, the value is subtracted from the value of the counter.

\addtocounter{mycounter}{-3}
Now the counter mycounter has the value 14 (17 - 3 = 14).

stepcounting

With the command \stepcounter{name} the counter name will be increased by 1. Here one speaks occasionally also of stepwise high-counting.

\stepcounter{mycounter}
Now the counter mycounter has the value 15 .

Assign counter value to another counter

If you want to transfer the counter value from one counter to another, you can do this with a combination of the commands value and setcounter \setcounter{counter1}{\value{counter2}}, where counter1 is assigned the value of counter2.

\setcounter{counter1}{\value{counter2}}

print counter value

With the command \the and the name of the counter name you could print the value of this counter.

\themycounter
Hint: There is no leading backslash at the counter name.

Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy