1

This question already has an answer here:

I'm using amsthm and thmtools to define custom theorem environments, definition environments, etc. All such environments share the same counter.

Is it possible to vary the numbering format depending on the section depth? I want to achieve the following numbering format:

1 Section

1.1 Theorem

1.2 Definition

1.1 Subsection

1.1.1 Theorem

1.1.2 Lemma

marked as duplicate by egreg, user13907, Thorsten, user31729, Masroor Sep 5 '14 at 8:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What do you use exactly thmtools for? – skpblack Sep 5 '14 at 1:14
0

You can prefix the theorem counter with a section-specific numbering scheme:

enter image description here

\documentclass{article}
\usepackage{amsthm,etoolbox}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}

\makeatletter
\@addtoreset{theorem}{section}% Reset theorem counter with every section
\@addtoreset{theorem}{subsection}
\@addtoreset{theorem}{subsubsection}
\newcommand{\theoremprefix}{}
\let\thetheoremsaved\thetheorem
\renewcommand{\thetheorem}{\theoremprefix\thetheoremsaved}
\let\sectionsaved\section
\patchcmd{\@startsection}{\par}{\renewcommand{\theoremprefix}{\csname the#1\endcsname.}}{}{}
\makeatother

\begin{document}

\section{Section}
\begin{theorem}
Th 1
\end{theorem}
\begin{definition}
Df 1
\end{definition}
\subsection{Subsection}
\begin{theorem}
Th 2
\end{theorem}
\begin{lemma}
Lm 1
\end{lemma}
\section{Two}
\begin{theorem}
Th 3
\end{theorem}
\begin{lemma}
Lm 2
\end{lemma}
\subsection{Other}
\begin{theorem}
Th 4
\end{theorem}
\subsection{Other 2}
\begin{definition}
Df 2
\end{definition}
1

i'm not sure if you want something like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\swapnumbers
\newtheorem{theorem}{Theorem}[section]
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\usepackage{thmtools}

\usepackage{xpatch}
\makeatletter
\newif\ifsection
\newif\ifsubsection
\preto\section{\sectiontrue\subsectionfalse}
\preto\subsection{\sectionfalse\subsectiontrue}
\patchcmd{\@xsect}% <cmd>
  {\ignorespaces}% <search>
  {\ifsection
    \numberwithin{theorem}{section}
    \else
    \numberwithin{theorem}{subsection}
    \fi
    \setcounter{theorem}{0}\relax\ignorespaces}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}

\section{Section}
\begin{theorem}
Th 1
\end{theorem}
\begin{definition}
Df 1
\end{definition}
\subsection{Subsection}
\begin{theorem}
Th 2
\end{theorem}
\begin{lemma}
Lm 1
\end{lemma}
\section{Two}
\begin{theorem}
Th 3
\end{theorem}
\begin{lemma}
Lm 2
\end{lemma}
\subsection{Other}
\begin{theorem}
Th 4
\end{theorem}
\subsection{Other 2}
\begin{definition}
Df 2
\end{definition}
\end{document}

enter image description here

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