35

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}
0

1 Answer 1

45

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}
3
  • 1
    +1 but I would say it is safest to use \setcounter{exe}{2} e.g. if you include the code twice by mistake. Dec 17, 2012 at 11:51
  • @AndrewSwann: Thanks for your comment. I have updated the answer to use that form in the main code, as was in fact my original intention (it was the one I mentioned in the text, albeit misspelt to begin with). Dec 17, 2012 at 11:53
  • Thank you very much for your answer! It is working!!! Thank's a lot!
    – Thanos
    Dec 17, 2012 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .