I am writing a report that has in-text exercises as well as end-of-chapter exercises. I want all the exercises to be numbered consecutively. I want the in-text exercises begin with theitalized word "Exercise", followed by the numbering. And for the end-of-chapter ones, I do not have the word "Exercise" in front, just the numbering.

I tried to do this using the \theoremstyle in amstext but the numbering do not come out correctly. Here is a minimal (non)-working example:

\section{First section}
Cite the second exercise  \ref{two}.  Cite the third exercise \ref{three}.

\begin{exer}  \label{one}   First exercise.    \end{exer}

End of Chapter Exercises

\stepcounter{exer}  \theexer.  \label{two}   Second Exercise.

\stepcounter{exer}  \theexer.  \label{three} Third Exercise.

When I run this code, I end up with the output

Cite the second exercise 1.  Cite the third exercise 1.

Exercise 1.  First exercise.

End of Chapter Exercises.

2.  Second Exercise.

3.  Third Exercise.

which is incorrect. If I replace latex code for the second and the third exercises with

\begin{exer}  \label{two} Second exercise.  \end{exer}

\begin{exer}  \label{three}  Third exercise.  \end{exer}

then the numbering come out correctly, but not in the format I need.

I'm really baffled. Your help is most appreciative. THANKS!

  • 2
    \refstepcounter is what you need. Be careful with spaces. – egreg Jun 2 at 22:35
  • Brilliant! Replacing \stepcounter with \refstepcounter solves my problem. THANKS! Follow up question: Could you elaborate on what you mean by "be careful with spaces"? – underflow Jun 2 at 23:30
  • It would be useful if you showed the definition of exer. In this particular case, spaces in the input don't really affect the output, but only because you're lucky. – egreg Jun 2 at 23:41
  • oops -- I forgot to cut and paste the definition of exer. Here it is: \theoremstyle{remark} \newtheorem{exer}{Exercise} – underflow Jun 3 at 0:09

Use \refstepcounter instead of \stepcounter, so that a proper value to be referenced is set.

On the other hand, I'd prefer a more abstract approach:



  {0pt}        % ABOVESPACE
  {0pt}        % BELOWSPACE
  {\upshape}   % BODYFONT
  {0pt}        % INDENT (empty value is the same as 0pt)
  {\upshape}   % HEADFONT
  {.}          % HEADPUNCT
  { }          % HEADSPACE
  {\thmnumber{#2}} % CUSTOM-HEAD-SPEC


\section{First section}

Cite the second exercise  \ref{two}.  Cite the third exercise \ref{three}.

First exercise.

\subsection*{End of Chapter Exercises}

Second Exercise.

Third Exercise.


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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