7

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

enter image description here

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}
9
  • 1
    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
  • 1
    @PaulGessler The answer - just not to the question? – cfr Feb 27 '14 at 3:37
  • 1
    @cfr the reason is the redefinition of \@toodeep made by enumitem: \def\@toodeep{% \ifnum\@listdepth>\enit@listdepth\relax \enit@toodeep \else \count@\@listdepth \global\advance\@listdepth\@ne \@ifundefined{@list\romannumeral\the\@listdepth}% {\expandafter\let \csname @list\romannumeral\the\@listdepth\expandafter\endcsname \csname @list\romannumeral\the\count@\endcsname}{}% \fi} This doesn't affect standard lists, but any non-standard environment (mdframed, in particular) controlling the nesting levels with \@toodeep will now allow... – Gonzalo Medina Feb 27 '14 at 4:54
10

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.