Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Please provide a minimal example. –  Marco Daniel Aug 10 '12 at 9:29
2  
just a guess but are you using \advance rather than \stepcounter ? –  David Carlisle Aug 10 '12 at 9:32

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer

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

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.