0

I am making use of \qedhere in proof environments in order to avoid extra space when the proof ends in an equation. I am wondering about why it behaves differently in different environments.

  • Apparently, \qedhere does not work in an equation environment, when using the showonlyrefs feature from the mathtools package? I get the following error: A <box> was supposed to be here. \end{equation}
  • When using the amsmath package, it does not give an error between a pair of $$, but it does not flush the \qed box to the right, so it does not behave as desired. The same goes for the gather environment.
  • It works in an align environment, but only if & is ever used, see Strange behavior by \qedhere in align environment without alignment mark (&)
  • It works as desired in square brackets \[\]

Here is a MWE:

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}
\begin{document}
    \begin{proof}
        Too much space afterwards:
        \[
        a=b.
        \]
    \end{proof}
    \begin{proof}
        Works fine:
        \[
        a=b.\qedhere
        \]
    \end{proof}
    \begin{proof}
        Not flushed right:
        $$
        a=b.\qedhere
        $$
    \end{proof}
    \begin{proof}
        Not flushed right:
        \begin{gather}
            a=b.\qedhere
        \end{gather}
    \end{proof}
    \begin{proof}
        Box completely misplaced:
        \begin{align}
        a=b.\qedhere
        \end{align}
    \end{proof}
    \begin{proof}
    Stuff in comments gives error.
%       \begin{equation}
%       a=b.\qedhere
%       \end{equation}
    \end{proof}
\end{document}

which looks like MWE

Why do I get these different behaviors, and what is the preferred way of using \qedhere?

1 Answer 1

2

Using $$ is not supported in LaTeX. So your third example must be dismissed.

Also, \qedhere is not compatible with numbered equations, independently on how they show or not with showonlyrefs. After all, where should the tombstone be placed when there is an equation number at the right margin?

Finally, align requires at least one & in order for \qedhere to work. (Never use align for a single equation.)

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{mathtools}
%\mathtoolsset{showonlyrefs}

\begin{document}

\begin{proof}
Too much space afterwards: (expected)
\[
a=b.
\]
\end{proof}

\begin{proof}
Works fine: (OK)
\[
a=b.\qedhere
\]
\end{proof}

%\begin{proof}
%Not flushed right: (unsupported)
%$$
%a=b.\qedhere
%$$
%\end{proof}

\begin{proof}
Not flushed right: (no, if you do right)
\begin{gather*}
a=b.\qedhere
\end{gather*}
\end{proof}

\begin{proof}
Box completely misplaced: (no)
\begin{align*}
a&=b \\
a&=b.\qedhere
\end{align*}
\end{proof}

\begin{proof}
Stuff in comments gives error. (no)
%   \begin{equation}
%   a=b.\qedhere
%   \end{equation}
\end{proof}

\end{document}

enter image description here

See my comments in parentheses.

2
  • Thanks, that makes sense! I get form this that basically all environments will work just fine with \qedhere, if you tell the compiler explicitely that they are supposed to be unnumbered, right? I overlooked this, because the last equations of my proofs have never had numbers so far. The difference is only about the way these environments handle this conflict between equation number and qed box, which happens in different ways for align, gather and equation.
    – hexcoffee
    Aug 18, 2022 at 9:23
  • I'm new to the showonlyrefs feature, so I learned now that the compiler can not figure out itself that there is no conflict between equation number and \qedhere when using showonlyrefs
    – hexcoffee
    Aug 18, 2022 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .