# Circumvent interaction between memoir and mdframed

I noticed that when I use mdframed in a memoir document I'm not able to change the margin lengths of any frame defined from mdframed. This appears to happen regardless of the place where I try to set their lengths.

Here is a MWE showing the problem.

\documentclass{memoir}

\usepackage[framemethod=tikz]{mdframed}

\definecolor{creamy}{HTML}{e2bf40}
\colorlet{callout-bg}{creamy!50}

\newmdenv[backgroundcolor=callout-bg]{newframed}

\begin{document}
\begin{newframed}[leftmargin=-10pt, rightmargin=10pt]
The leftmargin is \the\mdflength{leftmargin}. The rightmargin is \the\mdflength{rightmargin}.
\end{newframed}
\end{document}


Is there a way to circumvent this unwanted interaction?

• use tcolorbox instead of mdframed. Apr 22, 2021 at 21:07
• @UlrikeFischer I need to be able to use colored framed paragraphs that can span multiple pages. Does tcolorbox allow for this usecase? Apr 22, 2021 at 23:07
• @araruna that and much much more. IMO there isn't much reason to use mdframed any more Apr 23, 2021 at 4:58
• I've removed the memoir tag Apr 23, 2021 at 4:59
• Tcolorbox offers breakable boxes,and they are much more reliable than the one of mdframed. Mdframed has various problems here, e.g it can break to early or insert unwanted space. Apr 23, 2021 at 6:22

The issue is independent of memoir (the same happens with book). As explained in section 6.7 of the mdframed documentation you need the innermargin and outermargin options in two-side documents (the default mode for both memoir and book). Or alternatively you can use the leftmargin and rightmargin options but with the addition of the usetwoside=false option.

MWE

\documentclass{memoir}

\usepackage[framemethod=tikz]{mdframed}

\definecolor{creamy}{HTML}{e2bf40}
\colorlet{callout-bg}{creamy!50}

\newmdenv[backgroundcolor=callout-bg]{newframed}

\begin{document}

\begin{newframed}[innermargin=-10pt,outermargin=10pt]
The leftmargin is \the\mdflength{leftmargin}.
The rightmargin is \the\mdflength{rightmargin}.
\end{newframed}

\begin{newframed}[usetwoside=false,leftmargin=-10pt,rightmargin=10pt]
The leftmargin is \the\mdflength{leftmargin}.
The rightmargin is \the\mdflength{rightmargin}.
\end{newframed}

\end{document}


• This really solves the question. I saw this part on the manual and I indeed tried to use these options, but somehow they made no visual difference at first (10pt is not big enough) and I forgot to consider them in my "debug" MWE. Thank you. Apr 22, 2021 at 23:12