1

I would like to change the behaviour of enumerate inside certain theorem environments. In particular. I would like enumerate to number using the letters "a." "b." "c." etc rather than "1." "2." "3." etc in my "exercise" environment, but otherwise to behave normally, including in other theorem environments.

\documentclass{article}

\newtheorem{exercise}{Exercise}[section]

\begin{exercise}
\begin{enumerate}
   \item Question 1
   \item Question 2
\end{enumerate}
\end{exercise}

\end{document}
3
  • this will help -- tex.stackexchange.com/a/1853/197451
    – js bibra
    Jan 18, 2022 at 5:04
  • For future posts: Please provide a full example document in such a case, i.e. include also the \documentclass{article} etc into your code example, such that it will be compiled by LaTeX. This simplifies the answering Jan 19, 2022 at 10:29
  • @MaximilianKeßler thanks -- will do. Jan 19, 2022 at 18:37

1 Answer 1

2

I would suggest you use the enumitem package, which enables you to easily change the default style of your enumerate environments.

Combining this approach with the $\LaTeX$ hook system (texdoc hooks), we can modify the default labelling style within each exercise environment:

\documentclass{article}

\usepackage{enumitem}

\newtheorem{exercise}{Exercise}[section]

\AddToHook{ env/exercise/begin } { \setlist [enumerate] { label=\alph*. } }

\begin{document}

Start a list:
\begin{enumerate}
  \item foo
\end{enumerate}

List inside environment:
\begin{exercise}
  \begin{enumerate}
    \item Question 1
    \item Question 2
  \end{enumerate}
\end{exercise}

List after environment:
\begin{enumerate}
  \item foo
\end{enumerate}

\end{document}

Note also that the change of the label is contained inside the exercise environment, since \begin{...} also starts grouping, and we used the begin hook, which inserts our code after entering the exercise environment, but before processing its contents. Thus, we do not need to restore the behavior manually after the end of the exercise, as you observe in the example document.

2
  • +1 for a well formulated answer. If the user is using an old LaTeX without the hooks, then one can do a similar thing via the etoolbox package.
    – daleif
    Jan 19, 2022 at 11:30
  • Thank you, this works perfectly! Jan 19, 2022 at 18:11

You must log in to answer this question.

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