2

I am trying to create a custom theorem format using the thmtools package. However, I am running into problems with the alignment of the QED symbol. When I end the theorem with normal text, it placed the QED symbol at the end of the line, and when I end with an equation and use \qedhere, it places the QED symbol right next to the equation. However, I would like the opposite: for the QED to be at the end of the line with an equation, and right next to the period of regular text.

You can see my MWE below:

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{ifthen}
\usepackage{calc}

\declaretheoremstyle[
    spaceabove=10pt,
    headpunct={},
    headformat=\ifthenelse{ \equal{\NOTE}{} }%
    {% yes
    $\underset{%
        \raisebox{2pt}[0pt][0pt]{%
        \rule{\widthof{\text{\NAME\ \NUMBER}}+6ex}{.1ex}}%
        }{%
        \text{\NAME\ \NUMBER}\hfill%
        }$%
    }{% no
    $\underset{%
        \raisebox{5.5pt}[0pt][0pt]{%
        \rule{\widthof{\text{\NAME\ \NUMBER\hspace{1ex}$|$\hspace{1ex}\NOTE}}+6ex}{.1ex}}%
        }{%
        \text{\NAME\ \NUMBER\hspace{1ex}$\bm{|}$\hspace{1ex}\NOTE}\hfill%
        }$%
    }\newline,
    spacebelow=10pt,
    qed=\qedsymbol
]{thmdefault}

\declaretheorem[style=thmdefault]{Theorem}

\begin{document}

Here is some text.

\begin{Theorem}[Important Theorem]
    This is a theorem. Notice that this QED symbol is right next to my equation. I would like it at the end of that line. $$a^2 + b^2 = c^2\qedhere$$
\end{Theorem}

Here is some more text.

\begin{Theorem}[Another Theorem]
    This is another theorem. Notice that the QED symbol is placed at the end of the line. I would like it right next to this period.
\end{Theorem}

And here is a little more text.

\end{document}

(I included the large headformat option because the QED does not behave the same if it is not there.)

This seems like it should be a very simple problem with an easy solution (I am only beginning to learn LaTeX), but after a few days of searching, I cannot seem to find a solution.

4

You need to use \[...\] for your display math which sets \qedhere at the location you want. For the text-related adjustment, we redefine \qed to not include the \hfill:

enter image description here

\documentclass{article}
\usepackage{amsmath,amsthm,bm,thmtools}
\usepackage{ifthen}
\usepackage{calc}

\declaretheoremstyle[
  spaceabove=10pt,
  headpunct={},
  headformat=\ifthenelse{ \equal{\NOTE}{} }%
  {% yes
  $\underset{%
    \raisebox{2pt}[0pt][0pt]{%
    \rule{\widthof{\text{\NAME\ \NUMBER}}+6ex}{.1ex}}%
    }{%
    \text{\NAME\ \NUMBER}\hfill%
    }$%
  }{% no
  $\underset{%
    \raisebox{5.5pt}[0pt][0pt]{%
    \rule{\widthof{\text{\NAME\ \NUMBER\hspace{1ex}$|$\hspace{1ex}\NOTE}}+6ex}{.1ex}}%
    }{%
    \text{\NAME\ \NUMBER\hspace{1ex}$\bm{|}$\hspace{1ex}\NOTE}\hfill%
    }$%
  }\newline,
  spacebelow=10pt,
  qed=\qedsymbol
]{thmdefault}

\declaretheorem[style=thmdefault]{Theorem}

% Update \qed to remove \hfill
\DeclareRobustCommand{\qed}{%
  \ifmmode
    \mathqed
  \else
    \leavevmode\unskip
    \penalty 9999
    \hbox{}\nobreak\quad\hbox{\qedsymbol}
  \fi
}
\begin{document}

Here is some text.

\begin{Theorem}[Important Theorem]
This is a theorem. Notice that this QED symbol is right next to my equation.
I would like it at the end of that line.
\[
  a^2 + b^2 = c^2\qedhere
\]
\end{Theorem}

Here is some more text.

\begin{Theorem}[Another Theorem]
This is another theorem. Notice that the QED symbol is placed at the end of the line. 
I would like it right next to this period.
\end{Theorem}

And here is a little more text.

\end{document}
  • You say you redefine \qed but how do you know the original/default definition for it? I want to skip a line and center it below the final equation. Would be good to have a look at it first though. – voices Aug 31 '19 at 0:31
  • 1
    @tjt263: You can use \show\qed to see the definition of \qed, or find the definition in the original source code; in this case, amsclass.dtx. The .dtx is filled with documentation as comments, but you should be able to identify the definition. – Werner Aug 31 '19 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.