# Align equation counter with theorems

I have some code behaving like this:

Chapter 1

Section 1.1

Subsection 1.1.1

Definition 1.1.2

Theorem 1.1.3

Equation 1.1.1

I would like it to behave in this way:

Chapter 1

Section 1.1

Subsection 1.1.1

Definition 1.1.1.1

Theorem 1.1.1.2

Equation 1.1.1.3

Subsection 1.1.2

Equation 1.1.2.1

Theorem 1.1.2.2

Section 1.2

Equation 1.2.1

Definition 1.2.2

Here's my code

\counterwithin{equation}{subsection}

\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%
\theoremstyle{break}
\newtheorem{teor}[subsection]{MyThm}
\newtheorem{cor}[subsection]{MyCor}
\newtheorem{defn}[subsection]{MyDefinition}


To wrap it up I'd like:

• the section counter to be dependent only on the chapter counter
• the subsection counter to be dependent only on the section counter
• equations, theorems... to share a same counter, which only depends on the section/subsection counter

Do you have any advice in regard?

• Welcome to tex.sx. The workings of theorem numbering (with amsthm) are described in this answer: Theorem/Definition/Lemma problem — Numbering. Essentially, you should set \newtheorem{teor}{MyThm}[subsection] and then number the others by reference to [teor]. – barbara beeton Mar 12 at 18:20

Share the equation counter with the statements and modify \theequation to ignore a zero subsection number.

\documentclass{book}
\usepackage{amsmath,amsthm}

\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}

\renewcommand{\theequation}{%
\thesection.%
\ifnum\value{subsection}>0 \arabic{subsection}.\fi
\arabic{equation}%
}

\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%
\theoremstyle{break}
\newtheorem{theorem}[equation]{Theorem}
\newtheorem{corollary}[equation]{Corollary}
\newtheorem{definition}[equation]{Definition}

\begin{document}

\chapter{Chapter 1}

\section{Section 1.1}

\subsection{Subsection 1.1.1}

\begin{definition}
This should be Definition 1.1.1.1
\end{definition}

\begin{theorem}
This should be Theorem 1.1.1.2
$$\text{This should be Equation 1.1.1.3}$$
\end{theorem}

\subsection{Subsection 1.1.2}

$$\text{This should be Equation 1.1.2.1}$$

\begin{theorem}
This should be Theorem 1.1.2.2
\end{theorem}

\section{Section 1.2}

$$\text{This should be Equation 1.2.1}$$

\begin{definition}
This should be Definition 1.2.2
\end{definition}

\end{document}


• This solves the problem, however if definitions, theorems etc. are declared inside a section (and not a subsection) the counter is 1.1.0.1 (chapter, section, subsection, thing). Do you know how to display 1.1.1 without the 0 of the non-existin subsection? Thanks in advance – warm_fish Mar 12 at 22:30
• @warm_fish I find this numbering scheme confusing, but it's your document. Fixed. – egreg Mar 12 at 22:44