# \qed for theorems without proofs

It is common to place a \qed-Box at the end of a theorem statement (or lemma, corollary, ...) if we give no proof for that statement.

How can I do this in LaTeX? If I place a qed-box at the end of the statement there is an additional linebreak, which is inacceptable formating.

if you are using amsthm or an ams document class, this problem is addressed by an item in the ams author faq. this in turn links to an example document (that's the input; the output is also present) that covers quite a few of the possible situations in which such a marker could be wanted. the most extreme situations require some manual effort, but i believe that nearly all reasonable possibilities (including the non-proof ending with a display) are covered.

• links are not dead, but the link to the example document is on an ftp server. some institutions restrict access to ftp servers through strict firewalls. that is unfortunate. more unfortunate is the fact that the tool used at ams to update the web server trashes tex code (it doubles backslashes without warning), so posting a tex source file of this size is not reliable. – barbara beeton Oct 14 '16 at 15:01
• Oh, good point! I grabbed and re-uploaded the file at gist.github.com/wchargin/b3825f2dd3f17cf24532a8cf360a0e94. It compiles fine under pdflatex, so doesn't seem to have been mangled. – wchargin Oct 14 '16 at 20:32
• @wchargin -- files on a (linux-based) ftp server are reliable. it's the tool that posts files to be fed from the ams web server that corrupts nice well-behaved ascii. we can zip such files, and that's reliable, but not everyone finds unzipping them "obvious". – barbara beeton Oct 14 '16 at 21:13
• Ah, that makes more sense. Thanks for clarifying. – wchargin Oct 14 '16 at 22:28

With the theorem packages you would normally use \qed as described in this answer. Without those you use the commands below depending on if you want the filled square or empty.

When the line is too full for a square it will be placed on the new line, but since \hfill only works when there are characters on the line, the square will be placed left. You can precede \hfill by \null\nobreak to fix this. (\null inserts and empty \hbox and \nobreak is necessary to prevent this box from simply being placed on the previous line, where it'd be ineffective)

\documentclass[a4paper]{article}
\usepackage{amssymb} %% <- for \square and \blacksuare

\newcommand*{\QEDA}{\null\nobreak\hfill\ensuremath{\blacksquare}}%
\newcommand*{\QEDB}{\null\nobreak\hfill\ensuremath{\square}}%

\begin{document}

Lorem ipsum \QEDA

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod!?! \QEDB

\end{document}


### Note:

The \qed command from amsthm employs a few additional tricks. A fully featured version of the above commands (with an optional argument for the symbol to use) would read

\newcommand*{\QED}[1][$\square$]{%
\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
}


(\leavevmode makes the command usable outside a paragraph (don't do this, though) \unskip removes a preceding space if there is one, \hbox{} is the same as \null, \penalty9999 ensures that TeX will try its utmost to squeeze the symbol into the same line as the preceding text and \quad separates the symbol from the text by a bit.)

• This is not guaranteed to place the QED symbol at the end of the line – egreg Oct 14 '16 at 8:41
• @Circumscribe The edit doesn't guarantee the QED symbol goes at the end of the line either. – egreg May 8 '20 at 17:13
• @egreg: Um, good point. I simply assumed the edit accomplished what it said it did, but you're right. I'll retract my comment. – Circumscribe May 8 '20 at 17:33
• (I fixed the answer properly in the meantime.) – Circumscribe May 8 '20 at 19:49

Sometimes it is usefull to create a minimal example:

\documentclass{article}
\usepackage{amsmath,amsthm}
\newtheorem{lem}{Lemma}
\usepackage{lipsum}
\begin{document}
\begin{lem}
Text Text Text\qed
\end{lem}
\end{document}


Leave no space between the end of the text and \qed.

A more complex example.

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This theorem has no proof.\qed
\end{theorem}

\begin{theorem}
This theorem has no proof xxx xxxxx xxx xxxxx xxxx xxx.\qed
\end{theorem}

\begin{theorem}
This theorem has no proof xxx xxxxx xxx xxxxx xxxx xxx xxx.\qed
\end{theorem}

\begin{theorem}
This theorem has no proof xxx xxxxx xxx xxxxx xxxx xxx xxx xx.\qed
\end{theorem}

\begin{theorem}
This theorem has no proof xxx xxxxx xxx xxxxx xxxx xxx xxx xxxx.\qed
\end{theorem}

\end{document}


You could add the \qedsymbol to the end of your theorem automatically. The etoolbox package provides the means to tap into the end of an environment using \AtEndEnvironment{<env>}{<code>}. This adds <code> at \end{<env>}.

\documentclass{article}
\usepackage{amsthm}% http://ctan.org/pkg/amsthm
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newtheorem{theorem}{Theorem}%
\AtEndEnvironment{theorem}{\null\hfill\qedsymbol}%
\begin{document}
\begin{theorem}
This is an important theorem.
\end{theorem}
\end{document}


However, this is only beneficial if you do not also include a \qedsymbol with your proofs. Moreover, it may cause undesired effects if you end your theorem with an equation. Regardless, you have some options:

• Define a non-proof-theorem environment which adds this automatically; or
• add it manually using some of the other answers provided; or
• provide (say) a starred version of theorem (that is, theorem*) which does the above.
• Peter Grill gives a nice answer,it works! – user16950 Jul 26 '12 at 8:44
• This is not guaranteed to place the QED symbol at the end of the line. – egreg Oct 14 '16 at 8:40

Late to the party, but my answer is as follows:

To insert a QED symbol:

Case 1: Last line of text is to be centre-aligned:

\hfill <last line of code> \hfill $\square$


Case 2: Centre-alignement is not required:

<last line of code> \hfill $\square$


This works inside any environment and even if the last line is an equation, in which case you have to use $\displaystyle <equation>$ instead of 

Or if you like, use \lozenge instead of $\square$ to have a different QED symbol.

• Might not be such a good idea, it does not disencourage a page break before the square and if the line is full, the hfill will probably die and the square ends up at the left margin instead of the right. Have a look at the \qed implementation in amsthm, we see a lot of the constructions like you present here, they are not to be encouraged. – daleif Jan 30 '14 at 10:06

To get the symbol used for typesetting the QED, use \qedsymbol:

\documentclass{minimal}
\usepackage{amsmath,amsthm}
\newtheorem{theorem}{Theorem}
\def\eolqed{\hspace{\stretch1}\ensuremath\qedsymbol}
\begin{document}
\begin{theorem}Foo is a bar.\eolqed
\end{theorem}
\end{document}

• There is no need for \ensuremath here. – Werner Nov 7 '11 at 19:20
• This is not guaranteed to place the QED symbol at the end of the line. – egreg Oct 14 '16 at 8:40
• \def\eolqed{\hfill\qedsymbol} would also do the trick. – Nicolas Schmidt Mar 19 '19 at 14:05