7

I have created two counters

\newcounter{problem}[section]
\newcounter{solution}[problem]

As expected, problem resets every time section increases.

However, solution does not reset when problem increases.

What is the problem?

Pygmalion
  • 6,387
  • 4
  • 34
  • 68

2 Answers2

9

You have to use \stepcounter or \refstepcounter to trigger the reset code. If you set the value in other ways then you need to reset the other counter to 0 explicitly.

If you get \endcsname errors that is another problem and probably needs another question. But if you ask a question please give people half a chance of answering it by providing a complete (small) document that produces the error.

David Carlisle
  • 757,742
4

I suppose you want to present multiple solutions to a problem? Then you could do it like this:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\newcounter{problem}[section]
\newcounter{solution}[problem]
\renewcommand{\thesolution}{\arabic{problem}.\arabic{solution}}


\begin{document}

\section{one}
\stepcounter{problem}problem \theproblem\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\

\stepcounter{problem}problem \theproblem\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\

\section{one}
\stepcounter{problem}problem \theproblem\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\

\stepcounter{problem}problem \theproblem\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\
\stepcounter{solution}solution \thesolution\\

\end{document}

enter image description here

Tom Bombadil
  • 40,123
  • 2
    In such a case it would probably be better to treat problems and solutions as theorem like enviornments. Using amsthm and amsmath you can set-up this up with e.g. \theoremstyle{definition} \newtheorem{problem}{Problem} \theoremstyle{remark} \newtheorem{solution}{Solution} \numberwithin{solution}{problem} in the preamble to get the type of numbering you desire. – Andrew Swann Aug 10 '12 at 11:20