Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
See tex.stackexchange.com/questions/49085/… as it uses the end mark well. –  sandu Nov 28 '12 at 10:56

2 Answers 2

up vote 7 down vote accepted

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}
share|improve this answer
    
What a neat little package; perfect! –  Freddie Witherden Jun 5 '11 at 17:25

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}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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