1

I'm trying to enumerate the different theorem-like counters within each sections independently. I'm using the code I found on this link. However, theorems, lemmas, and definitions are not numbered in themselves, they are numbered consecutively.

My MWE is like that;

\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}
\begin{theorem}
    Th 2
\end{theorem}
\begin{definition}
    Df 2
\end{definition}

\subsection{Subsection}
\begin{theorem}
    Th 1
\end{theorem}
\begin{definition}
    Df 1
\end{definition}
\begin{definition}
    Df 2
\end{definition}

\begin{lemma}
    Lm 1
\end{lemma}
\begin{theorem}
    Th 2
\end{theorem}

\subsubsection{SubSubsection}
\begin{theorem}
    Th 1
\end{theorem}
\begin{definition}
    Df 1
\end{definition}
\begin{definition}
    Df 2
\end{definition}

\begin{lemma}
    Lm 1
\end{lemma}
\begin{theorem}
    Th 2
\end{theorem}


\section{Two}
\begin{theorem}
    Th 1
\end{theorem}
\begin{lemma}
    Lm 1
\end{lemma}


\end{document}

and it looks like this.

output of MWE

How can I fix this numbering sequence?

  • 1
    The code you are using is only for theorem, you have to do the same with definition and lemma – DG' May 12 '23 at 09:39
  • 1
    Seems you don't want to use the theorem counter for definition and lemma. So you should remove the optional argument [theorem] from the definitions of definition and lemma. – cabohah May 12 '23 at 09:56
  • Dear @cabobah your suggestion doesn't work as i want, when I removed the argument [theorem] from definition and lemma, the section and subsection numbers are also removed, and they do not appear next to the names. Morever, the explanations in the links you gave are not related to numbering. – Bluerose May 12 '23 at 11:10
  • Dear @DG when I add \newcommand{\definitionprefix}{} \let\thedefinitionsaved\thedefinition \renewcommand{\thedefinition}{\definitionprefix\thedefinitionsaved} \let\sectionsaved\section \patchcmd{\@startsection}{\par}{\renewcommand{\definitionprefix}{\csname the#1\endcsname.}}{}{} this code for definition before makeatother, nothing changed – Bluerose May 12 '23 at 11:17
  • Maybe share a link to the post where you got that code from? – DG' May 12 '23 at 11:53
  • It looks like you edited your question with the intention of reopening it. Is that correct? Could you explain why you'd like it reopened, given that you found an answer and the community thinks another question is also an answer? – Teepeemm May 17 '23 at 12:57
  • Dear @Teepeemm, since I thought the title of the question asked was similar to the previous questions, I changed the title of the question and reposted it. Did I think wrong? Although the question type is similar to the previous questions, the answer given is not the same as the previous question answers. – Bluerose May 24 '23 at 09:28

1 Answers1

0

I found the answer myself by applying @cabohah's suggestion correctly. Here is the MWE that works the way I want it to.

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

\makeatletter @addtoreset{theorem}{section}% Reset theorem counter with every section @addtoreset{theorem}{subsection} @addtoreset{theorem}{subsubsection}

@addtoreset{definition}{section} @addtoreset{definition}{subsection} @addtoreset{definition}{subsubsection}

@addtoreset{lemma}{section} @addtoreset{lemma}{subsection} @addtoreset{lemma}{subsubsection}

\newcommand{\definitionprefix}{} \let\thedefinitionsaved\thedefinition \renewcommand{\thedefinition}{\definitionprefix\thedefinitionsaved}

\newcommand{\lemmaprefix}{} \let\thelemmasaved\thelemma \renewcommand{\thelemma}{\lemmaprefix\thelemmasaved}

\newcommand{\theoremprefix}{} \let\thetheoremsaved\thetheorem \renewcommand{\thetheorem}{\theoremprefix\thetheoremsaved}

\let\sectionsaved\section \patchcmd{@startsection}{\par}{ \renewcommand{\theoremprefix}{\csname the#1\endcsname.} \renewcommand{\definitionprefix}{\csname the#1\endcsname.} \renewcommand{\lemmaprefix}{\csname the#1\endcsname.} }{}{}

\makeatother

\begin{document}

\section{Section}
\begin{theorem}
    Th 1
\end{theorem}
\begin{definition}
    Df 1
\end{definition}
\begin{theorem}
    Th 2
\end{theorem}
\begin{definition}
    Df 2
\end{definition}

\subsection{Subsection}
\begin{theorem}
    Th 1
\end{theorem}
\begin{definition}
    Df 1
\end{definition}
\begin{definition}
    Df 2
\end{definition}

\begin{lemma}
    Lm 1
\end{lemma}
\begin{theorem}
    Th 2
\end{theorem}

\subsubsection{SubSubsection}
\begin{theorem}
    Th 1
\end{theorem}
\begin{definition}
    Df 1
\end{definition}
\begin{definition}
    Df 2
\end{definition}

\begin{lemma}
    Lm 1
\end{lemma}
\begin{theorem}
    Th 2
\end{theorem}


\section{Two}
\begin{theorem}
    Th 1
\end{theorem}
\begin{lemma}
    Lm 1
\end{lemma}

\end{document}

This is the output: output of new MWE