# How to get more than 3 levels of nesting in mdframed environments?

Before I get to many of "don't do this as it does not look good", I have two modes of my documents:

1. Final mode: where there is ONLY one level of nested mdframed
2. Review mode: where there are numerous levels of nested mdframed, each one indicating information needed during the review process relevant to the text within the mdframed.

So, this requested usage is ONLY for my review mode.

The code below produces

But, Un-commenting out the two lines in the code yields

LaTeX Error: Too deeply nested.

I would like to get a larger number of nesting?

## Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}[frametitle={Outer Title 1},backgroundcolor=orange!25]
\begin{mdframed}[frametitle={Inner Title 2},backgroundcolor=cyan!25]
\begin{mdframed}[frametitle={Inner Title 3},backgroundcolor=yellow!25]
%\begin{mdframed}[frametitle={Inner Title 4},backgroundcolor=green]
%\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{document}

-
You need to increase the number of list levels defined. Simply loading enumitem would do it, but there's also a way to do it without loading a heavy package. –  Paul Gessler Feb 27 '14 at 3:20
@PaulGessler: Dammnn!! That works. BUT I am already including enumitem in my actual use case, that means that this is NOT going to solve my real problem... –  Peter Grill Feb 27 '14 at 3:22
So you have additional nesting in your actual usage that puts you once again over the nesting limit? –  Paul Gessler Feb 27 '14 at 3:24
@PaulGessler: Seems I can nest up to depth of 9 with enumitem, but I don't think I am exceeding that level. Back to figuring out what is going on in my actual use case. BTW, I think your suggestion is an answer. –  Peter Grill Feb 27 '14 at 3:27
@PaulGessler The answer - just not to the question? –  cfr Feb 27 '14 at 3:37

mdframed.sty has

\ifnum\mdf@envdepth >\tw@\@toodeep\else


in the definition of \mdf@preenvsetting and this prevents more than three levels of nesting. You can change this with a patch to the command:

\documentclass{article}
\usepackage{xcolor}
\usepackage{xpatch}
\usepackage{mdframed}
\makeatletter
\xpatchcmd{\mdf@preenvsetting}
{\mdf@envdepth >\tw@}
{\mdf@envdepth >20}
{}
{}
\makeatother
\begin{document}
\begin{mdframed}[frametitle={Outer Title 1},backgroundcolor=orange!25]
\begin{mdframed}[frametitle={Inner Title 2},backgroundcolor=cyan!25]
\begin{mdframed}[frametitle={Inner Title 3},backgroundcolor=yellow!25]
\begin{mdframed}[frametitle={Inner Title 4},backgroundcolor=green]
\begin{mdframed}[frametitle={Inner Title 5},backgroundcolor=magenta!20]
\begin{mdframed}[frametitle={Inner Title 6},backgroundcolor=olive!20]
\begin{mdframed}[frametitle={Inner Title 7},backgroundcolor=red!80!black]
\begin{mdframed}[frametitle={Inner Title 8},backgroundcolor=gray!50]
\begin{mdframed}[frametitle={Inner Title 9},backgroundcolor=blue!40]
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{document}


-