6

The last part of my proof is formatted in an alignat* environment. How do I make \qedhere appear correctly?

The naive approach (as you would do with align*):

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}
\begin{document}
  \begin{proof}
    \begin{alignat*}{2}
      &\quad& f &\le g \\
      \implies && f-a &\le g-a \\
      \implies && b(f-a) &\le b(g-a)
      \qedhere
    \end{alignat*}
  \end{proof}
  \lipsum[1]
\end{document}

produces an undesired result and the following warning:

The \qedhere command may not work correctly here
vog
  • 474
  • If you use ntheorem this is automatic. Actually, you don't have to type \qedhere: \end{proof} is enough. – Bernard Jul 22 '15 at 17:09

3 Answers3

5

The best thing to do is to add some final words to conclude the proof. If this is not an option, then some trickery would be required; here, using \tag*:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}

\begin{document}
  \begin{proof}
    \begin{alignat*}{2}
      &\quad& f &\le g \\
      \implies && f-a &\le g-a
      \tag*{\qedhere}
    \end{alignat*}
  \end{proof}
  \lipsum[1]
\end{document}

enter image description here

The ntheorem package claims to have a better management of the QED symbol, however, it doesn't give an out of the box proof environment unless the amsthm option is used:

\documentclass{article}
\usepackage{amsmath}
\usepackage[amsmath,amsthm,thmmarks]{ntheorem}
\usepackage{lipsum}

\begin{document}
  \begin{proof}
    \begin{alignat*}{2}
      &\quad& f &\le g \\
      \implies && f-a &\le g-a
    \end{alignat*}
  \end{proof}
  \lipsum[1]
\end{document}

enter image description here

so no need for \qedhere in this case and the placement is correct. However, take into account the accepted answer to Theorem packages: which to use, which conflict? and ponder whether to change to ntheorem.

Gonzalo Medina
  • 505,128
  • Neat trick. However, I get a steady warning about \linegoal, even after the 3rd and 4th run of LaTeX. What's going wrong here? Can the example be improved to run without persistent warnings? – vog Jul 22 '15 at 21:33
  • @vog You're right. I updated my answer with a simpler option (and no warnings). – Gonzalo Medina Jul 22 '15 at 21:56
  • I didn't switch to ntheorem, but went along with the \tag*{\qedhere} solution. Neat trick! – vog Jul 23 '15 at 08:11
2

if you're willing to make a manual adjustment, a modification of the \qedhere mechanism will work. (the value of the negative \vspace may need some adjustment depending on local conditions.)

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}
\begin{document}
  \begin{proof}
    \begin{alignat*}{2}
      &\quad& f &\le g \\
      \implies && f-a &\le g-a \\
      \implies && b(f-a) &\le b(g-a)
    \end{alignat*}
    \par \vspace{-1.7\baselineskip}
    \qedhere
  \end{proof}
  \lipsum[1]
\end{document}

output of example code

the idea for this approach was inspired by @egreg.

  • What is the advantage to the \tag*{\qedhere} solution presented in Gonzalo Medina's answer? – vog Mar 03 '16 at 00:10
  • @vog -- both approaches to this problem should work. it probably comes down to personal taste. the \tag* approach may be more reliable, in that, when you're at the bottom of a page, there is no likelihood that the tombstone will break to the new page, whereas there's a small chance that the \par \vspace might; putting \nobreak right after \par should help guard against that, but i haven't tested it thoroughly. (i really should.) – barbara beeton Mar 03 '16 at 01:54
0

The fact that \qedhere doesn't work with alignat should be considered as a bug of amsmath.

However, in this case you don't need alignat:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}

\begin{document}

\begin{proof}
\begin{alignat*}{2}
         &\quad& f &\le g \\
\implies && f-a &\le g-a
\qedhere
\end{alignat*}
\end{proof}
\lipsum[1]

\begin{proof}
\begin{align*}
                f &\le g \\
\implies\quad f-a &\le g-a  \qedhere
\end{align*}
\end{proof}
\lipsum[1]
\end{document}

As you see, the alignment in the second proof environment is the same as in the first one.

However, \qedhere should be used sparingly and ending a proof with a math display is not the best choice.

enter image description here

egreg
  • 1,121,712
  • Good point. I improved by MWE to make clear why I need alignat* instead of align* – vog Jul 23 '15 at 08:13
  • i've marked this question for attention when i get back to the office and can do some testing. however, it's not generally recommended to start a proof directly with a display. (there are known problems when a proof is started with itemize or enumerate, and i suspect this is related.) so that is a condition to be tested. – barbara beeton Jul 23 '15 at 08:27
  • @barbarabeeton The beginning of the proof is irrelevant. The same issue happens when the proof starts with a paragraph (as it does in my real use case, I just left it out for the MWE). – vog Jul 23 '15 at 08:43