9

I am using amsthm

\usepackage{amsthm}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}

and algorithm

\usepackage{algorithm, algpseudocode}
\makeatletter
\renewcommand\thealgorithm{\thechapter.\arabic{algorithm}}
%\@addtoreset{algorithm}{chapter}
\makeatother

In my text I have everything numbered consecutively in each chapter (Definition 3.1, Lemma 3.2, Theorem 3.3) except for the algorithms which have separate counter (Definition 3.1, Lemma 3.2, Algorithm 3.1, Theorem 3.3). How can I make it so that algorithms are numbered together with everything else? (Definition 3.1, Lemma 3.2, Algorithm 3.3, Theorem 3.4)

ondrejsl
  • 103

2 Answers2

5

Use [algorithm] in all your \newthorem so they use the algorithm counter instead of thm.

Beware though, if you use a floating environment and a non-floating environment with the same counter the algorithm may float past the theorem so come in the wrong order.

David Carlisle
  • 757,742
1

In the end I needed a different solution since I didn't have access to \newtheorem definitions.

\newcounter{common} % Create counter "common"

\makeatletter
\let\c@theorem\relax % drop existing counter "theorem" (you might not need this)
\makeatother

\usepackage{aliascnt}
\newaliascnt{theorem}{common} % let "theorem" be an alias for "common"
\newaliascnt{algorithm}{common} % let "algorithm" be an alias for "common"
ondrejsl
  • 103