# Why isn't my environment using mdframed working?

I am trying to make a new environment using mdframed but some of the options I am trying to define are not working.

Here is the code:

\documentclass[11pt, twosided]{book}
\usepackage[T1]{fontenc}
\usepackage[framemethod]{mdframed}
\usepackage{setspace}
\usepackage{xcolor}

\mdfdefinestyle{mdfexample1}{leftmargin=1cm,rightmargin=2cm,%
innerleftmargin=1cm,innerrightmargin=1cm,roundcorner=10pt}
\newmdenv[skipabove=15pt,
skipbelow=7pt,
rightline=true,
leftline=true,
topline=true,
bottomline=true,
linecolor=green,
backgroundcolor=green!10,
innerleftmargin=15pt,
innerrightmargin=15pt,
innertopmargin=15pt,
leftmargin=2cm,
rightmargin=2cm,
linewidth=2pt,
innerbottommargin=15pt,
roundcorner=10pt]{mBox}

\newenvironment{caixa}
{\begin{mBox}\onehalfspacing\small\color{blue}\ttfamily}{\end{mBox}}
\begin{document}
\begin{caixa}
\begin{itemize}
\item Parque 1
\item Parque 2
\end{itemize}
\end{caixa}

\begin{mdframed}[style=mdfexample1]
In any right triangle, the area of the square whose side is the hypotenuse
is equal to the sum of the areas of the squares whose sides are the two
legs.
\end{mdframed}
\end{document}


This is the result I am getting:

As you can see, it is not respecting several options I define, such as roundcorners, leftmargin and rightmargin. Does anyone know what is going wrong? Thank you in advance!

• setspace is also missing and the color definitions ! – user31729 Jun 13 '17 at 18:39
• @Moriambar Sorry, I am working in a book, so I had just copied the main package, I should work now! – LauraP Jun 13 '17 at 18:41
• @LauraP sure. A side note: color is superseded by xcolor so it is not necessary to use it – Moriambar Jun 13 '17 at 18:42
• @Moriambar: David will with furious anger lay his vengeance on you ;-) – user31729 Jun 13 '17 at 18:43
• Also mdframed already calls xcolor so… – Moriambar Jun 13 '17 at 18:47

The framemethod must be specified to be tikz, not the empty framemethod key.

If working in twoside mode, the outermargin and innermargin options should be used instead of rightmargin and leftmargin.

\documentclass[11pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\colorlet{azul}{blue}

\makeatletter % The code checks for twoside or oneside options
\if@twoside
\mdfdefinestyle{mdfexample1}{
innermargin=1cm,
outermargin=2cm,%
innerleftmargin=1cm,
innerrightmargin=1cm,
roundcorner=10pt}
\else
\mdfdefinestyle{mdfexample1}{
leftmargin=1cm,
rightmargin=2cm,%
innerleftmargin=1cm,
innerrightmargin=1cm,
roundcorner=10pt}
\fi
\makeatother

\newmdenv[skipabove=15pt,
skipbelow=7pt,
rightline=true,
leftline=true,
topline=true,
bottomline=true,
linecolor=green,
backgroundcolor=green!10,
innerleftmargin=15pt,
innerrightmargin=15pt,
innertopmargin=15pt,
leftmargin=2cm,
rightmargin=2cm,
linewidth=2pt,
innerbottommargin=15pt,
roundcorner=10pt]{mBox}

\newenvironment{caixa}
{\begin{mBox}\onehalfspacing\small\color{azul}\ttfamily}{\end{mBox}}
\begin{document}
\begin{caixa}
\begin{itemize}
\item Parque 1
\item Parque 2
\end{itemize}
\end{caixa}

\begin{mdframed}[style=mdfexample1]
In any right triangle, the area of the square whose side is the hypotenuse
is equal to the sum of the areas of the squares whose sides are the two
legs.
\end{mdframed}
\end{document}


• Thanks @Christian Hupfer, any idea why it isn't obeying the margins' options? – LauraP Jun 13 '17 at 18:50
• @LauraP: See the updated solution. The black frame in the screen shot is from showframe package, just ignore it – user31729 Jun 13 '17 at 19:00
• @LauraP: You're welcome. Happy TeXing! – user31729 Jun 13 '17 at 19:34