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'm using the exercise package together with memoir class. How do I number my exercises according to chapter number, in the same way that display equations are numbered? Here's a minimal example

\documentclass{memoir}

\usepackage{mathtools}
\usepackage{exercise}

\begin{document}
    \chapter{Foo}
        Lorem ipsum dolor sit amet
        \begin{Exercise}
            This should come out as Exercise 1.1
        \end{Exercise}
        \begin{Answer}
            Answer 1.1
        \end{Answer}

        \begin{Exercise}
            This should be Exercise 1.2
        \end{Exercise}

    \chapter{Bar}
        Consectetuer adipiscing elit
        \begin{Exercise}
            And this should be Exercise 2.1
        \end{Exercise}

        \begin{Exercise}
            Certainly this should be Exercise 2.2
        \end{Exercise}
        \begin{Answer}
            Answer 2.2
        \end{Answer}
\end{document}

I'm thinking of tapping into a counter variable in memoir or somewhere else. How do I go about it? I would like the numbering to also affect the Answer environment.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

I guess that

\usepackage{exercise,chngcntr}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}

should do what you need. The chngcntr package is used for binding a counter to another or to free one from another (with \counterwithout).

share|improve this answer
add comment

The exercise package provides the Exercise counter. Therefore, if you want the exercises numbered according to the chapter counter, you need:

\renewcounter{Exercise}[chapter]% Reset counter every chapter
\renewcommand{\theExercise}{\thechapter.\arabic{Exercise}}%

Exercise & answer

For any future reference on counters (how to reset them, so-called "master and slave" countering), consider reading the following UK TeX FAQ entries:

share|improve this answer
    
To help with future applications, what reference manual can I look up usage of \thechapter? (I found \arabic in vim-LaTeX Suite :help arabic) –  Kit Sep 4 '11 at 14:48
    
@Kit: I've added 2 references to my answer. –  Werner Sep 4 '11 at 14:54
add comment

If you're willing or happy to use the amsmath package, you could also set

\usepackage{amsmath,exercise}
\numberwithin{Answer}{chapter}
\numberwithin{Exercise}{chapter}
share|improve this answer
add comment

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.