7

I write the codes below to get a square as if to say q.e.d.

$$equation$$\textbox{\hfill\square}

Text\textbox{\hfill\square}

I want the square at the right extreme of the same line. I succeed only when the rest of the line has text and/or an equation within $ $, but not when it has an equation within $$ $$. In this case the square appears in the extreme right but in the next line but I want it on the same line.

Any help is appreciated.

Mico
  • 506,678
Karthik C
  • 379

2 Answers2

6

Use amsthm and its proof environment. If a proof ends with a displayed equation, itemize or enumerate, use \qedhere in the last line.

Example:

\documentclass{article}
\usepackage{amsthm}
\begin{document}
\begin{proof}
This proof ends with a displayed equation
\[
1+1=2.\qedhere
\]
\end{proof}

\begin{proof}
This proof ends normally,
\end{proof}
\end{document}

enter image description here

Never use $$...$$ in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

egreg
  • 1,121,712
2

You can load the ntheorem package with the thmmarks and amsmath options. Normally it can manage any display math environment, including the amsmath ones. Of course, it is incompatible with loading the amsthm package, but some compatibility is ensured by the amsthm option, which defines a proof environment and plain, definition and remark theorem styles similar to the amsthm ones.

The \qed command ensures an automatic placement of the qed symbol, which can be redefined through the \qedsymbol command. In case of a problem within a single theoremlike environment, you can inactivate the automatic placement with the \NoEndMark command and proceed to a manual placement. See § 2.6 of the doc for details.

By the way, you shouldn't use $$ ... $$ for displayed equations: it is pure TeX, and the vertical spacing can be incorrect. You should use \[ ... \] instead.

Here is an example with an align* environment, that demonstrates that no manual placement is necessary:

       \documentclass{article}
        \usepackage[utf8]{inputenc}
        \usepackage{mathtools}
        \usepackage[amsthm,  thmmarks,amsmath]{ntheorem}

        \begin{document}

        \begin{proof}
        This proof ends with two displayed equations:
        \begin{align*}
        1 + 1  &  =  2\\
        2+2 & =4.
        \end{align*}
        \end{proof}

        \begin{proof}
        This proof ends normally,
        \end{proof}

        \end{document}

enter image description here

Bernard
  • 271,350
  • What purpose does redefining \qed as \qedsymbol serve? – Karthik C Feb 03 '14 at 16:09
  • Customising the endmark of a theorem-like environment. \qed is defined per environment. It prints the value of \qedsymbol for the current environment and globally, it is empty. For the standard configuration (option standard), it is defined as \blacksquarefor proof environments. Otherwise it's up to you to define which environments require an "endmark", and you may decide different endmarks for different environments. – Bernard Feb 03 '14 at 18:52
  • Added an example to show the capabilities of ntheorem. – Bernard Feb 12 '14 at 23:45