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".

Werner
  • 603,163

1 Answers1

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}
Andrew Swann
  • 95,762
yo'
  • 51,322