# Get Definition and Theorem numberings to “follow”

I currently have the following set up:

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{amsthm}
\usepackage{amsmath,amssymb,amsfonts}

\theoremstyle{definition}
\newtheorem{definition}{Definition}
\numberwithin{definition}{section}
\newtheorem{theorem}{Theorem}
\numberwithin{theorem}{section}
\renewcommand{\qedsymbol}{$\blacksquare$}

\begin{document}
\section{Preliminaries}
\begin{definition} Def 1 \end{definition}
\begin{theorem} Thm 1  \end{theorem}
\end{document}


However, the numbering comes out as follows:

How can I get the Definition and Theorem numbering to "follow" one another according to section, i.e.

## Theorem 1.2

You're using wrong instructions:

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{amsthm}
\usepackage{amsmath,amssymb,amsfonts}

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section] % definitions are numbered according to sections
\newtheorem{theorem}[definition]{Theorem} % theorems share the numbering with definitions
\renewcommand{\qedsymbol}{$\blacksquare$}

\begin{document}

\section{Preliminaries}

\begin{definition}
Def 1
\end{definition}

\begin{theorem}
Thm 1
\end{theorem}

\end{document}


I also recommend typing in the environments that way, so they're more evident.

The theorem like environments provide something out of the box, but here is a more general another way, where a lot of counters can be coupled and follow each other -- this is not restricted to theorem like environments.

This allows to decouple the counters later on too, if requested.

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{amsthm}
\usepackage{amsmath,amssymb,amsfonts}

\usepackage{xassoccnt}

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{example}{Example}[section]

\renewcommand{\qedsymbol}{$\blacksquare$}

\DeclareCoupledCountersGroup{deftheoremexample}
\DeclareCoupledCounters[name=deftheoremexample]{definition,theorem,example}
\begin{document}
\section{Preliminaries}
\begin{definition}
Def 1
\end{definition}
\begin{theorem}
Thm 1
\end{theorem}
\begin{example}
$E=mc^2$
\end{example}
\begin{definition}
Def 2
\end{definition}
\begin{theorem}
Thm 2
\end{theorem}
\begin{example}
$E^2=(pc)^2+ (mc^2)^2$
\end{example}

\section{We don't want to follow any longer}

\ClearCoupledCounters{name=deftheoremexample}

\begin{definition}
Def 1
\end{definition}
\begin{theorem}
Thm 1
\end{theorem}
\begin{example}
$E=mc^2$
\end{example}
\begin{definition}
Def 2
\end{definition}
\begin{theorem}
Thm 2
\end{theorem}
\begin{example}
$E^2=(pc)^2+ (mc^2)^2$
\end{example}
\end{document}


• No need for complicated solutions; there's already a standard method. – egreg Jul 3 '16 at 20:20
• @egreg: True, but promoting coupled counters for other issues does not harm ;-) – user31729 Jul 3 '16 at 20:20