41

When a proof ends with a formula in equation or equation* environment, putting \qedhere after the equation would cause the QED symbol to appear in the right place. I.e. at the end of the line in which the equation appears. For example:

\begin{equation}
  x = y+z \qedhere
\end{equation}

However, I cannot get the same result when the formula is inside an align/align* environment using the same method:

\begin{align}
  x &= a+b \\
    &= y+z \qedhere
\end{align}

The square appears just after (y+z) and is not shifted to the right boundary of the page.

Here is a MWE:

\documentclass[a4paper]{article}
\usepackage{hyperref}
\usepackage{amsthm}
\usepackage[cmex10]{amsmath}
\interdisplaylinepenalty=2500
\usepackage{amssymb}

\title{Example to Show QED is Misplaced}
\author{}
\begin{document}
\begin{proof}
  This proof is typeset correctly:
  \begin{equation*}
    x = y + z \qedhere
  \end{equation*}
\end{proof}

\begin{proof}
  But this one not!
  \begin{align*}
    x & = u + v \\
    & = y + z \qedhere
  \end{align*}
\end{proof}

\end{document}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
MikeL
  • 1,001

2 Answers2

38

Change the order, this works just fine, amsthm after amsmath, otherwise it might be a bit hard for it to hook into align*

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\interdisplaylinepenalty=2500
\usepackage{amssymb}
\usepackage{hyperref}

\title{Example to Show QED is Misplaced}
\author{}
\begin{document}
\begin{proof}
This proof is typeset correctly:
\begin{equation*}
x = y + z \qedhere
\end{equation*}
\end{proof}

\begin{proof}
But this one not!
\begin{align*}
x & = u + v \\
& = y + z \qedhere
\end{align*}
\end{proof}

\end{document}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
daleif
  • 54,450
  • 5
    with the package order amsthm before amsmath, a warning is issued: Package amsthm Warning: The \qedhere command may not work correctly here on input line .... it's also documented in the first section of amsthdoc that "amsthm must be loaded after amsmath, not before." – barbara beeton Aug 29 '13 at 14:30
  • Another caveat, be sure to have all the & in the last line. If the preceding lines contained for example there & don't forget to use all of them on the last line too. – Yrogirg Oct 20 '15 at 01:58
  • When I do this, my QED symbol overlaps on top of the text inside the align* environment. Is there any way to fix this? – crxyz Jan 24 '23 at 02:26
  • 1
    @CrazyVideoGamer please post a question of your own including a suitable minimal example. – daleif Jan 24 '23 at 08:43
15

Section 5 of the amsthm package documentation contains the following.

When used with the amsmath package, version 2 or later, \qedhere will position the QED symbol flush right; with earlier versions, the symbol will be spaced a quad away from the end of the text or display. If \qedhere produces an error message in an equation, try using \mbox{\qedhere} instead.

However, when I tried this with your example I got a QED symbol one quad away from the end of the display, despite the fact that my distribution contains amsmath version 2.13. However, using

\tag*{\qedhere} 

instead solved the problem.

Ian Thompson
  • 43,767
  • 1
    see the second paragraph of section "1 introduction" of amsthdoc. (i had to check, because if it didn't already say that the loading order is important, i would have to add it to the list of bugs. glad i don't have to.) – barbara beeton Aug 29 '13 at 14:32
  • @barbarabeeton Consider the following code: \documentclass{article} \usepackage{amsmath} \usepackage{amsthm} \begin{document} \begin{proof} \begin{alignat*}{2} &x && =1 \\ &y && =2 \qedhere \end{alignat*} \end{proof} \end{document} amsmath is loaded before amsthm, yet latex issues a warning. The warning is not issued if align is used instead of alignat (but the result is ugly). Am I misusing alignat or is there an issue here? – brad Jul 20 '23 at 13:27
  • @brad -- alignat* should work the same as align*. I'm not able to test this right now, but surely this deserves its own question, so please post one. (That will also make ie easier to copy and paste the example code. I'm not at all sure why the first {2} is in braces, but that shouldn't make any difference.) Please also show the warning that is issued. – barbara beeton Jul 20 '23 at 15:34
  • @barbarabeeton : I did, cfr. here. Thank you. – brad Jul 20 '23 at 17:03