2

Just started learning LaTeX, because I'm trying to write a short math book. I started out using LyX, but ultimately I want more control over the typesetting, so I have to learn LaTeX.

Anyway, I want the \newenvironment{Example} that I defined to update its counter in the same way that \exercise does.

\exercise updates the way I want it to when I use \counterwithin{Exercise}{section}, but it does not work when I use \counterwithin{Example}{section}. I have no idea what the problem is, any help would be greatly appreciated.

Code that illustrates my problem:

\documentclass{memoir}
\usepackage{exercise,chngcntr}


\begin{document}

%Memoir
\setcounter{secnumdepth}{2}


\chapter{Chapter name}
\section{Section1}

\newcounter{Example}

\counterwithin{Exercise}{section} %Ties exercises counter to memoir section?
\counterwithin{Example}{section} %Use this to tie the example counter to the memoir sections?

\newenvironment{Example}{\begin{Exercise}[name={Example},
counter={Example}]}
{\end{Exercise}}

%Exercises below:

\begin{Exercise}
Exercise text
\end{Exercise}

\begin{Example}
Example text
\end{Example}

\begin{Exercise} %counter is the way I want it to be
Exercise text
\end{Exercise}

\section{Section2}

\begin{Exercise}
Exercise text
\end{Exercise}

\begin{Example}
Example text
\end{Example}

\begin{Example} %Counter does not increment
Example text
\end{Example}

\begin{Exercise}
Exercise text
\end{Exercise}

\end{document}

Edit: For clarification, the problem is in the second section, Section2, where the Example doesn't update: Example 2.1.1 and then Example 2.1.1 again, instead of Example 2.1.1 and then Example 2.1.2.

10
  • 1
    Try to move \counterwithin{Example}{section} after you define the Example environment.
    – Sigur
    Jun 27, 2015 at 10:47
  • @Sigur I tried. Examples still don't increment. Jun 27, 2015 at 10:50
  • I don't understand what you want. Please, give some example with numeration. Your code produces here Exercise 1.1.1 Example 1.1.1 Exercise 1.1.2. It makes sense since the section is 1.1. Do you want Example 1.1.2 instead of?
    – Sigur
    Jun 27, 2015 at 11:05
  • Not for me, I only see Exercise 1, etc. Not starting again with a new section.
    – MaxNoe
    Jun 27, 2015 at 11:06
  • 1
    Exsheets is a great package
    – MaxNoe
    Jun 27, 2015 at 13:37

1 Answer 1

1

The exercise package offers the command \renewcounter{<counter>}[<resetcounter>] to modify the behaviour of predefined counters.

So you need to add \renewcounter{Exercise}[section] to your preamble.

1
  • 1
    Tried this but it didn't make example increment in the second section. Jun 27, 2015 at 11:20

You must log in to answer this question.

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