# How to make equation numbering dependent on theorem numbering

I ask a variation of some questions previously posed.

What I have now is this: I want the equation numbers to follow the same numbering scheme as the theorems and definition. That is, I want the equation to be labelled (1.3) and the definition after it be labelled (1.4).

To further clarify, if we were in subsection 1.1, instead of section 1, I want to have theorem 1.1.1, theorem 1.1.2, equation 1.1.3 and definition 1.1.4.

Right now, the screenshot I posted uses the solution presented here.

I've also looked at this post. I tried to do that, but it completely ignored the "sectioning" I've done with the theorem numbers. Everything became 1, 2, 3... instead of 1.1, 1.2, 1.3, ...

Moreover, it makes the theorem numbers depend on the equation numbers, which is the opposite of what I want. I want the equation numbering to follow the theorem numbering. This is because I've already "fixed" the theorem numbering to how I want it. However, I'm open to more out-of-the-box suggestions.

The following is the code for the screenshot.

\documentclass[a4paper]{article}
\usepackage{amsmath, amsthm}
\setcounter{section}{0}

\newtheorem{thm}{Theorem}[section]
\numberwithin{equation}{section}
\newtheorem{ex}[thm]{Example}
\newtheorem{defn}[thm]{Definition}

\begin{document}

\section{Section Title}

\begin{thm}
Spaghettoni.
\end{thm}

\begin{thm}
Vermicelloni.
\end{thm}

\begin{proof}
Manicotti.
\begin{equation}
x^2 + y^2 = z^2
\end{equation}
\end{proof}

\begin{defn}
Maltagliati.
\end{defn}

\end{document}


The \newtheorem command has an optional argument in which you can specify an already existing counter to be used for numbering the theorems. This counter can be any LaTeX counter, including equation. So, for instance,

\numberwithin{equation}{section} % or whatever you prefer

\swapnumbers % I prefer this

\theoremstyle{plain}
\newtheorem{thm}[equation]{Theorem}
\newtheorem{prop}[equation]{Proposition}
\newtheorem{lem}[equation]{Lemma}
\newtheorem{cor}[equation]{Corollary}
\newtheorem*{notice}{Notice}

\theoremstyle{definition}
\newtheorem{dfn}[equation]{Definition}
\newtheorem{bigrem}[equation]{Remark}
\newtheorem{num}[equation]{} % a bit strange, but I do use it!
\newtheorem{exmp}[equation]{Example}


defines a whole series of “theorem-like” environments all of which are numbered in the same sequence as equations.

• Very useful, thanks. However, suppose my equations and theorems are not only inside a certain section, but a subsection. Then I'd like them to have an extra piece of numbering. If not, I'll have e.g. subsection 5.5.1, equation 5.5.1, theorem 5.5.2, ... which I find distasteful: equations and theorems should, in my opinion, always have one number more than whatever there is as a parent (sub(sub))section... I hope I'm getting my point through, though I'm aware that I'm not being extra clear. Aug 10, 2016 at 13:12
• To clarify: sure, in your first line I could change section by subsection, but then there's the ugly consequence which is that, in sections with no subsections, theorems and equations will have four numbers, which is one number too much! Aug 10, 2016 at 13:13
• @BrunoStonek:\numberwithin assumes that, if you want, say, equations to be numbered within subsections, you are not going to use them directly within sections; in other words, it assumes that all equations occur at the same sectioning level. It’s not impossible to arrange things for a different behavior, but you should specify unambiguously what this different behavior should look like. Perhaps you should ask a self-contained question concerning this specific issue.
– GuM
Aug 10, 2016 at 19:53