# changing numbering depth in certain subsection

I have a document with several sections, most of which contain subsections. In all but one of the sections, I want the theorem numbering to go by section depth. In one particular section, I want the numbering to go by subsection depth. I can accomplish this, but then I am having trouble with the counter in the later sections (where I am back to section depth). Here is an example:

\documentclass[11pt]{article}
\usepackage{amsmath, amssymb,amscd,amsthm}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}

\begin{document}

\section{The First Section}

\subsection{The First Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\subsection{The Second Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\section{The Second Section}
\numberwithin{theorem}{subsection}

\subsection{The First Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\subsection{The Second Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\section{The Third Section}
\numberwithin{theorem}{section}

\subsection{The First Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\subsection{The Second Subsection}

\begin{theorem}
a theorem
\end{theorem}

\begin{corollary}
a corollary
\end{corollary}

\end{document}


In this example, The Second Section is the one where I want to change the numbering depth, and so I add \numberwithin{theorem}{subsection}. This works great.

Now in The Third Section, I want to change the numbering back to just section depth, and so I add \numberwithin{theorem}{section}. The depth changes correctly, but the counter is still resetting after each subsection. In particular, I have

3 The Third Section

3.1 The First Subsection

Theorem 3.1. a theorem

Corollary 3.2. a corollary

3.2 The Second Subsection

Theorem 3.1. a theorem

Corollary 3.2. a corollary


What I want is:

3 The Third Section

3.1 The First Subsection

Theorem 3.1. a theorem

Corollary 3.2. a corollary

3.2 The Second Subsection

Theorem 3.3. a theorem

Corollary 3.4. a corollary


In other words, I want it to behave like the first section:

1 The First Section

1.1 The First Subsection

Theorem 1.1. a theorem

Corollary 1.2. a corollary

1.2 The Second Subsection

Theorem 1.3. a theorem

Corollary 1.4. a corollary


How can I fix this?

You need to also remove the resetting. There's a package dedicated to this. (Actually, there seem to be at least two!)

For example:

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amscd,amsthm,remreset}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}
\makeatletter
\newcommand*\notwithin[2]{%
\@removefromreset{#1}{#2}%
}
\makeatother
\begin{document}

\section{The First Section}
\subsection{The First Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}
\subsection{The Second Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}

\section{The Second Section}
\numberwithin{theorem}{subsection}
\subsection{The First Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}
\subsection{The Second Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}

\section{The Third Section}
\numberwithin{theorem}{section}
\notwithin{theorem}{subsection}
\subsection{The First Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}
\subsection{The Second Subsection}
\begin{theorem}
a theorem
\end{theorem}
\begin{corollary}
a corollary
\end{corollary}

\end{document}