9

I am using thmtools to create an example environment using \declaretheoremstyle and \declaretheorem. I am also modifying the style using the mdframed key, to create a frame, shade the background of the example environment, and give it rounded corners. I also want to format the title text, i.e., Example 1 and put a coloured line underneath the title before the example, but I can't figure out how to do this. I can see that it can be done using \newmdenv to create the example environment, but I want to stick with \declaretheoremstyle and \declaretheorem, since I am using it for all my other environments. Can anyone assist?

\documentclass[12pt,a4paper]{report}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{thmtools}

% example style
\declaretheoremstyle[
    headfont=\bfseries, 
    notebraces={[}{]},
    bodyfont=\normalfont\itshape,
    headpunct={},
    postheadspace=\newline,
    spacebelow=\parsep,
    spaceabove=\parsep,
    mdframed={
        backgroundcolor=red!20, 
            linecolor=red!30, 
            innertopmargin=6pt,
            roundcorner=5pt, 
            innerbottommargin=6pt, 
            skipbelow=\parsep, 
            skipbelow=\parsep } 
]{myexamplestyle}

% example environment - thmtools
\declaretheorem[
    style=myexamplestyle,
    name=Example,
    numberwithin=chapter
]{example}

\begin{document}
\begin{example}[Example 1]
something
\end{example}
\end{document}
10

Something like this?

\documentclass[12pt,a4paper]{report}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{lipsum}% just to generate text for the example

% example style
\declaretheoremstyle[
    headfont=\bfseries, 
    notebraces={[}{]},
    bodyfont=\normalfont\itshape,
    headpunct={},
    postheadspace=\newline,
    postheadhook={\textcolor{red}{\rule[.6ex]{\linewidth}{0.4pt}}\\},
    spacebelow=\parsep,
    spaceabove=\parsep,
    mdframed={
        backgroundcolor=red!20, 
            linecolor=red!30, 
            innertopmargin=6pt,
            roundcorner=5pt, 
            innerbottommargin=6pt, 
            skipabove=\parsep, 
            skipbelow=\parsep } 
]{myexamplestyle}

% example environment - thmtools
\declaretheorem[
    style=myexamplestyle,
    name=Example,
    numberwithin=chapter
]{example}

\begin{document}
\chapter{Test}
\begin{example}[Additional text]
\lipsum[4]
\end{example}
\end{document}

enter image description here

|improve this answer|||||
  • 1
    +1: Didn't know the key mdframed of thmtools ;-) -- Nice. – Marco Daniel Apr 23 '13 at 15:42

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.