External margins of embedded newmdenv environments

In the code:

\documentclass{article}
\usepackage[framemethod=default]{mdframed}
\newmdenv[backgroundcolor=red]{tBox}
\newmdenv[leftmargin=1cm,linecolor=blue]{aBox}
\begin{document}
\begin{aBox}\begin{tBox}text\end{tBox}text\end{aBox}
\end{document}


the leftmargin of the aBox environment affects the leftmargin of the tBox environment: is this expected?

-

1 Answer

I don't know if the package author (Marco Daniel) intended nested mdframed environments to work this way, but it seems that the inner environment simply inherits the settings of the outer environment and then adds its own settings on top of that. If you don't want the inner environment to be (additionally) indented, add leftmargin=0cm to its specification.

\documentclass{article}
\usepackage[framemethod=default]{mdframed}
\newmdenv[leftmargin=0cm,backgroundcolor=red]{tBox}
\newmdenv[leftmargin=1cm,linecolor=blue]{aBox}
\begin{document}
\begin{aBox}\begin{tBox}text\end{tBox}text\end{aBox}
\end{document}


-
Interesting. I thought it would be the behaviour by default. – pluton Sep 3 '12 at 20:11
@pluton: No. \newmdenv passes the optional argument to setkeys which works also for nested environments. – Marco Daniel Sep 4 '12 at 6:16