# Improper alignment of qed-like symbol when using equation to end

I use this code to define a symbol that I put at end of (maths) examples in my file.

\newcommand\xqed[1]{%
\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
\newcommand\demo{\xqed{$\bigcirc$}}


And I use it like follows:

\begin{defn}The spectrum is:
\begin{equation*}
\sigma(T) = \{ \lambda : (T-\lambda I)^{-1} \text{ does not exist} \}.
\end{equation*}
\demo
\end{defn}


Which looks like this:

I want the circle symbol on the same line as the equation. How do I do that? If I put the \demo on the line before the \end{equation*}, it looks even worse; it's pretty much only two spaces to the right of the equation.

-

Look at packages amsthm and ntheorem that provide answers for this. For example the former package defines a proof environment and the \qedhere command just suitable for your needs.

With these packages the procedure for defining theorems uses also the concept of "theorem style":

% default style
\newtheorem{thm}{Theorem} % defines a "thm" counter;
\newtheorem{cor}[thm]{Corollary} % numbering in common with thm
\theoremstyle{definition}
\newtheorem{defin}[thm]{Definition}

-
Thanks. With ntheorem, how do I make it so the theorems, defns, lemmas, etc. number successively? Eg, I want: 1.1.1 Theorem, then 1.1.2 Defn, not 1.1.1 Theorem, then 1.1.1 Defn. –  P.A May 11 '11 at 19:45
@P.A.: I'll add it in the answer. –  egreg May 11 '11 at 20:12
I already have that, but that produces: 1 Thm, 2 Eg, 3 Thm, 4 Defn etc. I want the section numbers: 1.1.1 Thm, 1.1.2 Eg, 1.1.3 Thm, 1.2.1 Defn for example. Adding \numberwithin{equation}{section} doesn't seem to change it. I appreciate your help. –  P.A May 11 '11 at 20:18
@P.A. This is basic LaTeX: define the first environment by \newtheorem{thm}{Theorem}[section] –  egreg May 11 '11 at 20:27
THANK YOU! You're a lifesaver. –  P.A May 11 '11 at 20:33

\def\qeds{\qed\par\medskip}