[Tex/LaTex] QED at end of Theorem (definition-style) Environment

amsthmtheorems

Apologize if this is a duplicate.

\documentclass[12pt]{extbook}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{etoolbox}
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\AtEndEnvironment{example}{\qed}%
%example
\begin{document}
\begin{example}
For example, if $E$ is the set of even numbers,
\begin{equation*}
\{x \in E: x = 2\}
\end{equation*}
is the set of all even numbers $x$ such that $x = 2$. Of course, there is only one even number equal to $2$, so 
\begin{equation*}
\{x \in E: x = 2\} = \{2\}\text{.}
\end{equation*}
\end{example}
\end{document}

enter image description here

Can I somehow move \qed up one line, to the right of the equation environment by changing the example environment definition?

Best Answer

With the ntheorem package, you have an automatic placement of \qedsymbol, and it's easy to have several types of \qedsymbols if you use the thmmarks option. The amsthm option provides a partial compatibility with the layouts defined in amsthm, but the syntax to define new theorem-like environments is more intuitive. Finally, the thref option provides extended refencing possibilities (compatible with cleveref).

\documentclass[12pt]{extbook}
\usepackage{amsmath, amssymb}
\usepackage[thmmarks, amsmath, thref]{ntheorem}
\theoremstyle{definition}
\theorembodyfont{\normalfont}
\theoremsymbol{\ensuremath{\square}}
\newtheorem{example}{Example}[section]

\begin{document}

\begin{example}
For example, if $E$ is the set of even numbers,
\begin{equation*}
\{x ∈ E: x = 2\}
\end{equation*}
is the set of all even numbers $x$ such that $x = 2$. Of course, there is only one even number equal to $2$, so
\begin{equation*}
\{x ∈ E: x = 2\} = \{2\}\text{.}
\end{equation*}
\end{example}

\end{document} 

enter image description here