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?
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?
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.
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}
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
\advance
rather than\stepcounter
? – David Carlisle Aug 10 '12 at 9:32