1

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?

4

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
\begin{equation}
\text{This should be Equation 1.1.1.3}
\end{equation}
\end{theorem}

\subsection{Subsection 1.1.2}

\begin{equation}
\text{This should be Equation 1.1.2.1}
\end{equation}

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

\section{Section 1.2}

\begin{equation}
\text{This should be Equation 1.2.1}
\end{equation}

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

\end{document}

enter image description here

| improve this answer | |
  • 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
  • 2
    @warm_fish I find this numbering scheme confusing, but it's your document. Fixed. – egreg Mar 12 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.