Need \qedhere to be flush with the right margin in cases environment

How can I do this?

When I put \qedhere in cases environment, the square is between the margins somewhere. It is not where the square appears in the usual proof environment, at the right margin.

\documentclass{amsart}
\usepackage{amssymb, amsmath, amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem*{ut}{Theorem}

\begin{document}

\begin{proof}

$$X(m,n)= \begin{cases} x(n),\\ x(n-1)\\ x(n-1)\qedhere \end{cases}$$
\end{proof}

\begin{ut}The sky is blue.\end{ut}

\begin{proof}Duh.\end{proof}

\end{document}


Abuse gathered:

\documentclass{amsart}
\usepackage{amssymb, amsmath, amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem*{ut}{Theorem}

\begin{document}

\begin{proof}
$\begin{gathered}[b] X(m,n)= \begin{cases} x(n),\\ x(n-1)\\ x(n-1) \end{cases} \\ \end{gathered} \qedhere$
\end{proof}

\begin{ut}The sky is blue.\end{ut}

\begin{proof}Duh.\end{proof}

\end{document}


In my opinion this is not the right place, as the baseline should be determined by X(m,n).

You could place the \qedhere outside the cases and raise the box. Or, see follow up to avoid having to recalculate the raise amount for each different cases environment.

\documentclass{amsart}
\usepackage{amssymb, amsmath, amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem*{ut}{Theorem}

\begin{document}

\begin{proof}

$\raisebox{1.2\baselineskip}{\displaystyle X(m,n)= \begin{cases} x(n),\\ x(n-1)\\ x(n-1) \end{cases}} \qedhere$
\end{proof}

\begin{ut}The sky is blue.\end{ut}

\begin{proof}Duh.\end{proof}

\end{document}


If you didn't want to have to calculate the shift each time, you could use the stackengine package, with \abovebaseline[-\dp\strutbox]{...} in lieu of the \raisebox{shift length}{...}.

• oh that looks right. by the way, how did you know to use value 1.2? – Forever Mozart Jan 6 '16 at 12:15
• @ForeverMozart Trial and error, knowing it to be approximately 1\baselineskip. See my edited answer to see how to avoid having to calculate the value for each different cases. – Steven B. Segletes Jan 6 '16 at 12:16

Following @egreg's suggestion as to the placement of the qed symbol, there's almost nothing to do: just replace $$…$$ with $…$. One more illuùminating example of why the latter is preferable:

\documentclass{amsart}
\usepackage{amssymb, amsmath, amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem*{ut}{Theorem}

\begin{document}

\begin{proof}[Proof 1]

$X(m,n)= \begin{cases} x(n), \\ x(n-1)\\ x(n-1) \end{cases} \qedhere$
\end{proof}
\vskip4ex

\begin{proof}[Proof 2]

$$X(m,n)= \begin{cases} x(n), \\ x(n-1) \\ x(n-1) \end{cases} \qedhere$$

\begin{ut}The sky is blue.\end{ut}

\begin{proof}Duh.\end{proof}

\end{proof}

\end{document}