12

I have created my own theorem environment like this

\newtheoremstyle{mythmstyle}{}{}{}{}{\scshape}{.}{ }{}
\theoremstyle{mythmstyle} \newtheorem{mythm}{Theorem}

How do I add the QED symbol (the white rectangle) into this custom environment? The \qedhere should work for it too, in case I need it.

Enchilada
  • 2,313

2 Answers2

6

One option would be to use the thmtools package as a front-end for amsthm:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
  spaceabove=\topsep, spacebelow=\topsep,
  headfont=\normalfont\scshape,
  notefont=\mdseries, notebraces={(}{)},
  bodyfont=\normalfont,
  postheadspace=1em,
  qed=\qedsymbol
]{mythmstyle}
\declaretheorem[style=mythmstyle]{theorem}

\begin{document}

\begin{theorem}
test
\end{theorem}

\begin{theorem}
test
\[
a\qedhere
\]
\end{theorem}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
6

Since you're using the amsthm package, you could simply redefine the package's \@endtheorem macro to include the \qed instruction, which will place an empty square box at the far right end of the theorem's last line. It's necessary to surround such a redefinition with a pair of \makeatletter and \makeatother instructions because the @ symbol is (deliberately) special in LaTeX. The following MWE shows how this may be achieved.

\documentclass{article}
\usepackage{amsthm}
% redefine the \@endtheorem macro
\makeatletter  
\def\@endtheorem{\qed\endtrivlist\@endpefalse } % insert `\qed` macro
\makeatother

\newtheoremstyle{mythmstyle}{}{}{}{}{\scshape}{.}{ }{}
\theoremstyle{mythmstyle} 
\newtheorem{mythm}{Theorem}

\begin{document}
\begin{mythm}[Pythagoras]
Consider a right triangle with sides of length $a$, $b$, and 
$c$, and assume w.l.o.g.\ that $a\le b<c$. Then $a^2+b^2=c^2$. 
\end{mythm}
\end{document}

enter image description here

Note that this approach, though simple, isn't quite perfect because the qed symbol won't be placed correctly if the theorem ends with a displayed equation. In such cases, you should probably follow the approach provided in Gonzalo's answer, which employs the powerful thmtools package.

Mico
  • 506,678
  • 1
    Will your solution affect all theorem like environments? How to do this only for one kind (example for example, not for the others theorem, corollary, etc...) – Sigur Apr 19 '14 at 16:36
  • 3
    @Sigur - To limit the scope of the proposed solution to a specific theorem style (e.g., mythmstyle), be sure to define all other theorem-like environments of your document before redefining \@endtheorem and setting up any new theorem styles and associated theorem-like environments (e.g., mythm). – Mico Apr 19 '14 at 22:06
  • @Mico Can you also show how to redefine the qed sign locally for this specific theorem style? Doing \renewcommand\qedsymbol{something} makes changes globally. But grouping it inside \@endtheorem, \def\@endtheorem{\renewcommand\qedsymbol{something}\qed\endtrivlist\@endpefalse} seems to work fine. Do you recommend this approach? – tush Jun 18 '23 at 12:21