8

I'm trying to include a $\blacktriangle$ at the end of a framed environment using the mdframed package.

However, my code is somehow not working properly. Let me explain what I'm doing:

\documentclass[12pt,twoside]{report}
\usepackage[brazil]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fouriernc}
\usepackage[margin=2cm]{geometry} 
\usepackage{amsmath,amsthm,amssymb}
\usepackage{thmtools}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}

\declaretheoremstyle
[
spaceabove=0pt, spacebelow=0pt, headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)}, headpunct={\newline}, headindent={},
postheadspace={ }, postheadspace=4pt, bodyfont=\normalfont, qed=$\blacktriangle$
]{mystyle}

{\theoremstyle{mystyle}
\newmdtheoremenv[%
outermargin = 1.3cm , %
leftmargin = 0pt , rightmargin = 0pt , %
innerleftmargin = 5pt , innerrightmargin = 5pt , %
innertopmargin = 5pt, innerbottommargin = 5pt , %
backgroundcolor = blue!10 , %
align = center , % align the environment itself (left, center, rigth)
nobreak = true, % prevent a frame from splitting
hidealllines = true , %
topline = true , bottomline = true , %
splittopskip = \topskip , splitbottomskip = 0pt , %
skipabove = 0.5\baselineskip ,  skipbelow = 0.3\baselineskip]
{example}{Exemplo}[chapter]}

\begin{document}
\section{Introduction}
Lorem ipsum sed nulla id risus adipiscing vulputate.

\begin{example}
Um consumidor financiou a compra de um veículo pagando 48 parcelas de \$800,00 mensais e a taxa de juros cobrada pela concessionária foi de 1,2\% a.m.. Qual era o valor à vista do automóvel adquirido?
\newline
\textbf{Solução:}
\newline
$PV = 800 \times \left[ \dfrac{1,012^{48}-1}{1,012^{48}\times 0,012} \right] \newline
PV = 800 \times \left[ \dfrac{0,772820}{0,021274} \right] \newline
PV = \$29.061,79$
\end{example}

Lorem ipsum sed nulla id risus adipiscing vulputate.
\end{document}

I've done lots of attempts and I had no success so far in putting the $\blacktriangle$ at the end of my mdframed framed environment. That's what I'm getting so far:

enter image description here

Could someone give me a hint of what I'm doing wrong?

cmhughes
  • 100,947
Rod
  • 183

1 Answers1

9

Here's a solution that borrows from the solution to Shaded theorems (thmtools) spanning pages

screenshot

The idea is to define an mdstyle

\mdfdefinestyle{myframedstyle}{%
    outermargin = 1.3cm , %
    ....

which is then hooked into the thmtools style declaration:

    preheadhook={\begin{mdframed}[style=myframedstyle]},
    postfoothook=\end{mdframed},

You'll notice that I have used the command

\declaretheorem[style=mystyle,numberwithin=chapter,title=Exemplo]{example}

to declare your new theorem.

Here's a complete MWE to play with.

% arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass[12pt,twoside]{report}
\usepackage[margin=2cm]{geometry} 
\usepackage{amsmath,amsthm,amssymb}
\usepackage{thmtools}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}

\declaretheoremstyle
[
    spaceabove=0pt, spacebelow=0pt, headfont=\normalfont\bfseries,
    notefont=\mdseries, notebraces={(}{)}, headpunct={\newline}, headindent={},
    postheadspace={ }, postheadspace=4pt, bodyfont=\normalfont, qed=$\blacktriangle$,
    preheadhook={\begin{mdframed}[style=myframedstyle]},
    postfoothook=\end{mdframed},
]{mystyle}

\declaretheorem[style=mystyle,numberwithin=chapter,title=Exemplo]{example}
\mdfdefinestyle{myframedstyle}{%
    outermargin = 1.3cm , %
    leftmargin = 0pt , rightmargin = 0pt , %
    innerleftmargin = 5pt , innerrightmargin = 5pt , %
    innertopmargin = 5pt, innerbottommargin = 5pt , %
    backgroundcolor = blue!10 , %
    align = center , % align the environment itself (left, center, rigth)
    nobreak = true, % prevent a frame from splitting
    hidealllines = true , %
    topline = true , bottomline = true , %
    splittopskip = \topskip , splitbottomskip = 0pt , %
    skipabove = 0.5\baselineskip ,  skipbelow = 0.3\baselineskip}

\begin{document}
\section{Introduction}
Lorem ipsum sed nulla id risus adipiscing vulputate.

\begin{example}
    Um consumidor financiou a compra de um veículo pagando 48 parcelas de \$800,00 mensais e a taxa de juros cobrada pela concessionária foi de 1,2\% a.m.. Qual era o valor à vista do automóvel adquirido?
    \newline
    \textbf{Solução:}
    \newline
    $PV = 800 \times \left[ \dfrac{1,012^{48}-1}{1,012^{48}\times 0,012} \right] \newline
    PV = 800 \times \left[ \dfrac{0,772820}{0,021274} \right] \newline
    PV = \$29.061,79$
\end{example}

Lorem ipsum sed nulla id risus adipiscing vulputate.
\end{document}

Following a chat with Gonzalo, thmtools now has an mdframed key, which can be used as follows (for example)

\documentclass[12pt,twoside]{report}
\usepackage[margin=2cm]{geometry} 
\usepackage{amsmath,amsthm,amssymb}
\usepackage{thmtools}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}

\declaretheoremstyle
[   spaceabove=0pt, spacebelow=0pt, headfont=\normalfont\bfseries,
    notefont=\mdseries, notebraces={(}{)}, headpunct={\newline}, headindent={},
    postheadspace={ }, postheadspace=4pt, bodyfont=\normalfont, qed=$\blacktriangle$,
    mdframed={   outermargin = 1.3cm , %
    leftmargin = 0pt , rightmargin = 0pt , %
    innerleftmargin = 5pt , innerrightmargin = 5pt , %
    innertopmargin = 5pt, innerbottommargin = 5pt , %
    backgroundcolor = blue!10 , %
    align = center , % align the environment itself (left, center, rigth)
    nobreak = true, % prevent a frame from splitting
    hidealllines = true , %
    topline = true , bottomline = true , %
    splittopskip = \topskip , splitbottomskip = 0pt , %
    skipabove = 0.5\baselineskip ,  skipbelow = 0.3\baselineskip}
]{mystyle}

\declaretheorem[style=mystyle,numberwithin=chapter,title=Exemplo]{example}

\begin{document}
\section{Introduction}
Lorem ipsum sed nulla id risus adipiscing vulputate.

\begin{example}
    Um consumidor financiou a compra de um veículo pagando 48 parcelas de \$800,00 mensais e a taxa de juros cobrada pela concessionária foi de 1,2\% a.m.. Qual era o valor à vista do automóvel adquirido?
    \newline
    \textbf{Solução:}
    \newline
    $PV = 800 \times \left[ \dfrac{1,012^{48}-1}{1,012^{48}\times 0,012} \right] \newline
    PV = 800 \times \left[ \dfrac{0,772820}{0,021274} \right] \newline
    PV = \$29.061,79$
\end{example}

Lorem ipsum sed nulla id risus adipiscing vulputate.
\end{document}
cmhughes
  • 100,947