# Nested mdframed environments and footnotes

Suppose that you have two mdframed environments, one nested inside the other, and a footnote in the first mdframed environment but not in the second. See the MWE example below.

\documentclass{article}

\usepackage{mdframed}

\begin{document}

\begin{mdframed}
Test frame\footnote{Test footnote}
\begin{mdframed}
Test nested frame
\end{mdframed}
\end{mdframed}

\end{document}


And here is what the same example looks like without the \footnote command.

There are (at least) two problems here. The first of course is that, with the footnote, the nested mdframed environment is too large and goes outside the right margin. The second problem is that, as the footnote appears in the first mdframed environment, it should be appearing at the end of the first mdframed environment, not the second. I suspect these problems are related (it's probably worth noting that if you move the footnote command into the second mdframed environment, everything is the correct size).

Any idea what's going on here or how to fix it?

• For the footnotes, footnote package could help you; maybe writing your code into savebox environment ... – juanuni May 24 '15 at 3:18

Use tcolorbox instead of mdframed:

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[arc=0mm,boxrule=1pt,colback=white]
Test frame\footnote{Test footnote}
\begin{tcolorbox}[arc=0mm,boxrule=1pt,colback=white]
Test nested frame
\end{tcolorbox}
\end{tcolorbox}
\end{document}

• +1, but un-fortunately I need to be able to have un-break-able boxes inside un-break-able boxes =/ – Jonathan Gleason May 24 '15 at 12:15
• @JonathanGleason So what? Although tcolorbox can made breakable boxes, by default those like of my MWE are unbreakable. – Fran May 24 '15 at 15:23