Tx · LaTeX & TikZ

How to Make Theorem Numbering Start at 0 in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Define the style

    Use \newtheoremstyle for spacing and fonts, not for counter values.

  2. 2. Create the environment

    Declare the theorem environment with \newtheorem before changing its counter.

  3. 3. Set the counter

    Set the counter to -1 so the first theorem increment displays as 0.

The \newtheoremstyle command changes the appearance of theorem-like environments: spacing, font, punctuation, and indentation. It does not determine the starting value of the theorem counter.

To make the first theorem numbered 0, define the environment and then set its counter to -1. When the first theorem starts, LaTeX increments the counter from -1 to 0.

Basic solution

Here is a complete compilable example using the amsthm package:

\documentclass{article}
\usepackage{amsthm}

\newtheoremstyle{zero-numbered}
  {6pt}       % Space above
  {6pt}       % Space below
  {\itshape}  % Body font
  {}          % Indentation
  {\bfseries} % Head font
  {.}         % Punctuation after theorem head
  {.5em}      % Space after theorem head
  {}          % Head specification

\theoremstyle{zero-numbered}
\newtheorem{theorem}{Theorem}

% The first theorem increments this value to 0.
\setcounter{theorem}{-1}

\begin{document}

\begin{theorem}
This is the first theorem, so it is numbered 0.
\end{theorem}

\begin{theorem}
This is the second theorem, so it is numbered 1.
\end{theorem}

\end{document}

The output is labeled “Theorem 0” and “Theorem 1”. The package required here is amsthm, which provides both \newtheoremstyle and the standard theorem-environment machinery.

Why the value must be −1

A theorem counter is incremented when the theorem environment begins. Therefore, setting it to 0 before the first theorem does not produce Theorem 0; it produces Theorem 1:

\setcounter{theorem}{0} % First theorem will be 1

To obtain 0 after the automatic increment, use:

\setcounter{theorem}{-1} % First theorem will be 0

The counter must be set after \newtheorem{theorem}{Theorem}, because that declaration creates the theorem counter. Setting an undefined counter produces an error.

Sharing the counter with other environments

If several environments share one sequence, reset the counter belonging to the sequence—not each environment separately. For example:

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\setcounter{theorem}{-1}

\begin{document}

\begin{lemma}
This is Lemma 0.
\end{lemma}

\begin{theorem}
This is Theorem 1 because both environments share the theorem counter.
\end{theorem}

\end{document}

The optional argument [theorem] in the \newtheorem declaration tells LaTeX to use the existing theorem counter for the lemma environment.

Starting at 0 in every section

You can also number theorems within sections:

\newtheorem{theorem}{Theorem}[section]

This normally produces numbers such as 1.1, 1.2, and 2.1. The [section] option automatically resets the theorem counter to zero whenever a new section begins. Consequently, setting the counter to -1 only once is not enough: the next section reset will make the first theorem number 1 again.

For current LaTeX releases, add a command hook so the counter is changed after each section reset:

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[section]

% Set the initial value before the first section.
\setcounter{theorem}{-1}

% Set it again after every section has reset the counter.
\AddToHook{cmd/section/after}{\setcounter{theorem}{-1}}

\begin{document}

\section{First section}
\begin{theorem}
The first theorem is 1.0.
\end{theorem}

\begin{theorem}
The next theorem is 1.1.
\end{theorem}

\section{Second section}
\begin{theorem}
The first theorem here is 2.0.
\end{theorem}

\end{document}

The hook version assumes that the document uses ordinary, unstarred \section commands. The cmd/section/after hook also runs after \section*, even though a starred section does not increment the section counter or reset the theorem counter; in a document containing starred sections, use the manual method below after each numbered section instead.

If you need compatibility with an older LaTeX installation, put \setcounter{theorem}{-1} manually immediately after each unstarred \section command instead:

\section{First section}
\setcounter{theorem}{-1}

The section number itself still starts at 1 in this example. Only the theorem number within each section starts at 0.

Common mistakes

Trying to put the counter change in \newtheoremstyle

A style declaration has arguments for vertical spacing, fonts, indentation, punctuation, and heading layout. It has no argument for the initial counter value. Keep the style and counter configuration separate.

Setting the counter to 0

Because theorem environments increment their counter automatically, \setcounter{theorem}{0} makes the first theorem number 1. Use -1 when the first displayed number must be 0.

Changing \thetheorem instead

You can redefine how a counter is printed with \renewcommand{\thetheorem}{...}, but that changes only the displayed representation. It does not change the counter’s internal value and can make references, numbering, or hyperlinks confusing. \setcounter is the direct solution when the sequence itself should begin at 0.

Forgetting shared counters

If definitions, lemmas, and theorems share a counter, changing theorem affects the whole sequence. If they are declared independently, each environment has its own counter and must be configured separately.

References

  1. The amsthm package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.