7

In my document I wish to provide example questions with solutions. I am currently doing this using the amsthm package as follows:

\documentclass{article}

\usepackage{lmodern}
\usepackage{amssymb,amsthm}

\newtheoremstyle{examplesty}         % Name
            {}                   % Above skip 
            {}                   % Below skip
            {\upshape}           % Body font
            {}                   % Indent
            {\bfseries} % Head font
            {}                   % Head body punct
            {1em}                % Space after head
            {}                   % Heading

% Examples rejig the theorem environment
\theoremstyle{examplesty}
\newtheorem{example}{Example}[section]

% Solutions use a modified proof environment
\newenvironment{solution}
               {\let\oldqedsymbol=\qedsymbol
                \renewcommand{\qedsymbol}{$\blacktriangleleft$}
                \begin{proof}[\bfseries\upshape Solution]}
               {\end{proof}
                \renewcommand{\qedsymbol}{\oldqedsymbol}}

\begin{document}
 \section{Test Section}
 \begin{example} This is an example problem \end{example}
 \begin{solution} This is a solution to an example problem. \end{solution}
\end{document}

My problem is that the spacing between the headings and bodies is different for examples and solutions. Moreover, solutions have a period after them, which looks odd. Is it possible to rectify these issues or am I guilty of trying to hammer in a nail with an old shoe?

  • See http://tex.stackexchange.com/questions/49085/ntheorem-and-thmtools-seem-incompatible as it uses the end mark well. – sandu Nov 28 '12 at 10:56

2 Answers2

12

You can use the thmtools front-end to easily interact with (for example) amsthm; this will easily give you consistency in the spacing. Here's an example showing how your definitions would look like:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
numberwithin=section
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no
]{solstyle}
\declaretheorem[style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}

\begin{document}

\section{Test section}

text text text
\begin{example}
text text text
\end{example}
text text text

text text text
\begin{solution}
text text text
\end{solution}
text text text

\end{document}
Gonzalo Medina
  • 505,128
1

The remove the period:

\makeatletter
\newenvironment{solution}
               {\let\oldqedsymbol=\qedsymbol%
                \def\@addpunct##1{}%
                \renewcommand{\qedsymbol}{$\blacktriangleleft$}%
                \begin{proof}[\bfseries\upshape Solution]}%
               {\end{proof}%
                \renewcommand{\qedsymbol}{\oldqedsymbol}}
\makeatother

To modify the length you can use the odd solution:

\def\@addpunct##1{\hspace*{1em}}
Marco Daniel
  • 95,681