\qed for theorems without proofs
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.
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
\quad\hbox{#1}%
}
(\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.)
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}