[Tex/LaTex] Start theorem counter from specific number

counterstheorems

I have defined a new theorem and I would like it to start from a specific number(let's say 3). At first I thought of using \addtocounter{\theexe}{3}(where exe is the new theorem) but I get an error stating that No counter '0' defined.

What I did next was to (re)define my counter using \renewcommand*{\theexe}{0} but I still get the same message. How can my counter be forced to start from 3. My code is

\documentclass[a4paper,11pt]{article}
\newtheorem{exe}{Problem}
\renewcommand*{\theexe}{0}

\begin{document}
\addtocounter{\theexe}{3}
\begin{exe}
This is the third problem
\end{exe}
\end{document}

Best Answer

exe is a LaTeX counter, and \theexe is a macro for formatting/displaying the current value of the counter (and is by default set to \arabic{exe}).

Redefining \theexe with \renewcommand will not change the underlying counter, and redefining it to always be 0 will cause all values of the counter to be displayed as zero.

Instead, you should be using the LaTeX counter commands, such as \setcounter and \addtocounter. While you have tried the latter, you tried passing the current display value of the counter instead of the name of the counter.

Note also that the exe environment automatically adds one to the counter (which starts off set to zero).

The correct syntax is \setcounter{exe}{2} (or \addtocounter{exe}{2}) to achieve that the number of the exe counter used in the first exe environment should be 3. As Andrew Swann has pointed out, it's probably safter to use the \setcounter version as there will not be any issues in case the line is accidentally duplicated, whereas the \addtocounter version would act twice.

\documentclass[a4paper,11pt]{article}
\newtheorem{exe}{Problem}
\setcounter{exe}{2}
\begin{document}
\begin{exe}
This is the third problem
\end{exe}
\end{document}
Related Question