# mdframed nested frametitle bug

When nesting frames the inner most frametitle is used. The frametitle for all these is frame3.

\documentclass{book}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}[frametitle={frame1}]
asdf
\begin{mdframed}[frametitle={frame2}]
134
\begin{mdframed}[ frametitle={frame3}]
asdf1324
\end{mdframed}
\end{mdframed}
\end{mdframed}
\end{document}


(mdframed v1.4)

-
First time I see such a using. ;-). Note that this can't be splitted well. –  Marco Daniel Mar 21 '12 at 10:31
Not sure what you mean that it can't be splitted well? Everything seems to work but the title(may not be perfect but works for what I'm trying to do). I suppose basically whatever function is not "reentrant" in that it uses a "global variable" for the frame title. What happens is the inner frame ends up overwriting the outer frame which is displayed after(for some reason, possibly to get the size right) the content of the frame. Should be an easy fix by just putting the title in a "local variable". –  Uiy Mar 21 '12 at 11:54

EDIT: I uploaded a new test version to github. Please check it out.

https://github.com/marcodaniel/mdframed

With the current version you can't change this behavior. To assign the frame title I am using a group and the contents is saved in a box. To get a global access to the box I need the command \global. So in your case I overwrite the last frame title.

This is the best answer I can provide so far

-
In some other questions I had several answers that used a global stack. Maybe you can use the interpretations it as a quick and easy solution? (simply push the title on the "stack" on each nesting then pop them when ready to use) –  Uiy Apr 14 '12 at 23:02
@Uiy: Do you have a link? –  Marco Daniel Apr 14 '12 at 23:02
tex.stackexchange.com/questions/51070/… My guess is, any time you use the title text, just convert to using the stack... need to push it at the start of the environment and then pop it and use it right when it is displayed... this should reduce all issues unless you have to deal with measuring issues in which case you might try poping it and using it right before the geometrical calculations. –  Uiy Apr 14 '12 at 23:17
@Uiy: I remember this question. I will think about this tomorrow. –  Marco Daniel Apr 14 '12 at 23:25
@Uiy: Please see my update. –  Marco Daniel Apr 27 '12 at 23:14

I also had problems with nested boxes using mdframed inside a beamerposter document (nested boxes are quite common on posters). I decided to give tcolorbox a try, and it has no problems with arbitrarily nested boxes (this is example is stolen from the CTAN package example file):

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\section{Boxes in boxes}
\begin{tcolorbox}[colback=yellow!10!white,colframe=yellow!50!black,
every box/.style={fonttitle=\bfseries},title=Box]
\begin{tcolorbox}[enhanced,colback=red!10!white,colframe=red!50!black,
colbacktitle=red!85!black,
\begin{tcolorbox}[beamer,colframe=blue!50!black,title=Box inside box inside box]
An now for something completely different: Boxes!\par\medskip
\newtcbox{\mybox}{nobeforeafter,tcbox raise base,colframe=green!50!black,colback=green!10!white,arc=0pt}
\mybox{This} \mybox{is} \mybox{another} \mybox{box.}
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}
\end{document}


Have a look at the beautiful documentation with lots of examples. Especially noteworthy are the available skins, e.g. the "enhanced" skin which uses TikZ internally. With this, you can create box designs you would not have thought are possible in Latex, have a look here.

So while this might not solve your problem, it provides a good alternative for typesetting nested framed boxes in Latex.

-