[Tex/LaTex] How to adjust the QED symbol to appear just after the last word in a proof

amsthm

Whenever I finish a proof I tend to put the little square just after the last word, but by using the /begin{proof} /end{proof} environment it appears always at the end of the line. It seems like its definition would include the /hfill command but I don't know how to leave it out. How can I fix it?

Best Answer

You have to patch the \qed command.

\documentclass{article}

\usepackage{amsthm}

%% using xpatch 
\usepackage{xpatch}
\xpatchcmd{\qed}{\hfill}{}{}{}

%% Or without any package
%\DeclareRobustCommand{\qed}{%
%  \ifmmode % if math mode, assume display: omit penalty etc.
%  \else \leavevmode\unskip\penalty9999 \hbox{}\nobreak%\hfill
%  \fi
%  \quad\hbox{\qedsymbol}}

\begin{document}

\begin{proof}
 This is some proof.
\end{proof}

\end{document}

enter image description here

The separation is \quad. You can change that also similarly, i.e.,

\xpatchcmd{\qed}{\quad}{\space}{}{}  %% \space may be \hspace{<length>}