(click anywhere to close)
OPEN MENU

[LaTeX] Counters

category: Writing | course: LaTeX | difficulty:

As you’ve seen in last chapter, LaTeX automatically keeps separate counters for every type of section. But, what’s really good about this, is that it also does the same for nearly everything – tables, figures, table of contents, and so on. Because this concept of counters keeps popping up all over LaTeX, I wanted to do a chapter on it here that explains how you can customize them, and add your own counters.

Setting & Getting Counters

To set an existing counter, use

\setcounter{counter}{value}

To get the current value of a certain counter, as text, use

\the<NameOfTheCounter>

\setcounter{section}{4}
The value is: \thesection
LatexSettingGettingCounters

If you don't want it as text, but as a number to use in calculations, use \value{counter}.

Changing Counters

To increment an existing counter by a certain amount, use

\addtocounter{counter}{value}

This value can be negative, if you want to decrement it.

To create a new counter, use

\newcounter[counter]{name}

If you supply the optional argument counter, which must be an existing counter, this new counter is reset every time counter is changed.

Changing the Numbering System

It’s possible to display your counters using a different system than the regular Arabic numbers you’re used to.

Command

Description

Example

\alph{counter}

Prints counter using lowercase alphabetic characters

a, b, c, …

\Alph{counter}

Prints counter using uppercase alphabetic characters

A, B, C, …

\arabic{counter}

Prints counter using regular numbers. Default.

1, 2, 3, …

\roman{counter}

Prints counter using lowercase roman numbers

i, ii, iii, …

\Roman{counter}

Prints counter using uppercase roman numbers

I, II, III, …

\newcounter{mysections}
\addtocounter{mysections}{2}

\section*{\Roman{mysections} A Section Numbered Differently}
Lorem Ipsum...
LatexNumberingSystems

Useful Counters to Remember

By default, the table of contents only registers sections to a maximum of three levels deep. To set this to something else, change the counter tocdepth.

By default, all sections are numbered to a depth of 2 – so, for example, sections and subsections are numbered, but subsubsections aren’t. To change this, use the counter secnumdepth.

\setcounter{secnumdepth}{4}

\section{La}
\subsection{Lala}
\subsubsection{Lalala}
\paragraph{Lalalala}
LatexCountersDepth

All other counters are accessed by simply typing its name, as we've already seen with section.

Use \pagenumbering{numbering system} if you just want to change the numbering system of the current page.

CONTINUE WITH THIS COURSE
Do you like my tutorials?
To keep this site running, donate some motivational food!
Crisps
(€2.00)
Chocolate Milk
(€3.50)
Pizza
(€5.00)