6

I was wondering if there was a way to modify the theorem environment so that it interacted with sections/subsections as follows:

\section{}
\subsection{}
\begin{ex} Whatever
\end{ex}

\begin{ex}Whatever
\end{ex}



\subsection{}

\begin{ex} Whatever

\end{ex}

Would output something like

1
1.1

Exercise 1.1.1


Exercise 1.1.2



1.2

Exercise 1.2.1

Where \begin{ex} is just an environment for an "exercise".

2

1 Answer 1

8

You can use the built-in feature for theorem numbering:

\documentclass{article}

\usepackage{amsthm} % not necessary

\newtheorem{ex}{Exercise}[subsection]

\begin{document}

\section{}

\subsection{}

\begin{ex}
Whatever
\end{ex}

\begin{ex}
Whatever
\end{ex}

\subsection{}

\begin{ex}
Whatever
\end{ex}

\end{document}
3
  • 2
    This is a standard feature, not only of amsthm.
    – egreg
    Dec 20, 2012 at 8:37
  • @egreg And there exists \newtheorem without amsthm?
    – yo'
    Dec 20, 2012 at 8:49
  • 2
    Yes, of course; amsthm and the similar ntheorem just add to the kernel functionality.
    – egreg
    Dec 20, 2012 at 8:50

You must log in to answer this question.

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