In a book with chapters and sections, I would like to number (and \label for possible reference elsewhere) the exercises at the end of each section as, for example, Exercise 1.2.3, for the third exercise at the end of the second section in the first chapter. It needs to be "dynamic" so that everything is automatically adjusted in the event that I add other exercises, move sections or chapters, etc. (I've already \labeled each chapter and each section.)

  • 1
    Welcome to TeX! You can add a \label in the definition of exercise environment. A complete example is welcome. Commented Jul 2, 2020 at 2:14
  • LaTeX's \label-\ref system is fully dynamic, in the sense that a couple of recompile rounds will full update the cross-reference call-outs. If I understand your query correctly, though, you seem to be asking for a rather different type of "dynamic" -- viz., making the argument of a \label instruction (and off all related \ref instructions too!) associated with an exercise environment adjust so that it incorporates the current number of the exercise. If this interpretation is correct, the only sane piece of advice that can be given is, "Don't Even Think About Doing This."
    – Mico
    Commented Jul 2, 2020 at 4:51
  • (continuation of previous comment). If my interpretation is not correct, do please clarify what it is that you're trying to achieve.
    – Mico
    Commented Jul 2, 2020 at 4:53
  • Incidentally, it would really help if you provided some information about how the exercise environment is defined.
    – Mico
    Commented Jul 2, 2020 at 4:54
  • Please add some clarifications to your question. What exactly do you refer to with the term "label" here? Is it the \label command or do you refer to the exercise number?
    – leandriis
    Commented Jul 2, 2020 at 5:45

1 Answer 1


Assuming the sections are already numbered as chapter.section, you should be able to declare


in the document preamble after whatever package you use to set up exercises. Check that package documentation to see if it offers an option to do this by itself.

You can separately control the display of the number and whether the counter gets reset every section by using two separate declarations


for the formatting and


for the resetting.

  • 1
    \counterwithin has been in the LaTeX kernel for a while.
    – egreg
    Commented Jul 2, 2020 at 8:58
  • Ha! Thanks from an oldie, to whom 2018 is like yesterday. I'll add it to answer, if you don't mind. Commented Jul 2, 2020 at 9:37
  • Of course you can!
    – egreg
    Commented Jul 2, 2020 at 9:49

You must log in to answer this question.

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