QED at end of Theorem (definition-style) Environment

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}


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

• Why no use \qedhere inside equation. (\{x \in E: x = 2\} = \{2\}\text{.}\qedhere)? – skpblack Nov 10 '14 at 1:43
• @skpblack: that doesn’t work in this situation. It works inside a proof environment, but not inside a theorem-style environment: a \qedhere on its own produces nothing, and a \qed inside the equation comes out immediately following the equation text, not right-aligned as one wants. – Peter LeFanu Lumsdaine Feb 26 '16 at 13:39

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}


It is rather bad style to end an example with a displayed material. If you cannot reformulate it, there is an exemplary solution. If you want the square to be moved to the right, you can replace \qed by \tag*{\qed}, but certainly only for unnumbered equations.

\documentclass[12pt]{extbook}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{etoolbox}
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\AtEndEnvironment{example}{\qed}%
\newtheorem{exampleqed}[example]{Example}
\AtEndEnvironment{exampleqed}{}%
%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}

\begin{exampleqed}
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{.}
\qed
\end{equation*}
\end{exampleqed}
\end{document}

• This certainly works for my needs. Just simple and quick. If worked just fine for an equation at the end of a section in which I prove a theorem using the IEEEtran template. Thanks! – kentropy Feb 12 '20 at 21:24