I'm moving from mdframed
to using tcolorbox
, and I'm almost where I want to be.
Using mdframed
, I can use the singleextra
and firstextra
parameters to add nodes to my frame, and this changes the height of the frame as a whole (i.e. if my new node sticks out above the frame, the height of the entire thing is increased; ditto if my new node sticks out below the frame). This makes my life easy.
Using tcolorbox
, I can use the overlay
parameter to add nodes to the frame, but the size does not adjust automatically. There is, if you include \tcbuselibrary{hooks,skins}
(not sure which one exactly does it) an enlarge top by
parameter that will add space needed so thew node that sticks out above the frame doesn't overlap previous content.
The MWE below shows the use of an overlay and enlarge top by
.
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,hooks}
\usepackage{lipsum}
\tcbset{
frogbox/.style={
enhanced,
colback=green!10,
colframe=green!65!black,
enlarge top by=5.5mm,
overlay={
\foreach \x in {2cm,3.5cm} {
\begin{scope}[shift={([xshift=\x]frame.north west)}]
\path[draw=green!65!black,fill=green!10,line width=1mm] (0,0) arc (0:180:5mm);
\path[fill=black] (-0.2,0) arc (0:180:1mm);
\end{scope}
}
}
}
}
\tcbset{
app/.style={
overlay app={%
\draw(frame.north)--(frame.south);
}
}
}
\begin{document}
\lipsum[1]
\begin{tcolorbox}[frogbox,title=My title]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\lipsum[2]
\begin{tcolorbox}[frogbox,app,title=My title]
This is a \textbf{tcolorbox}.\par
Here, we apply a second overlay.
\end{tcolorbox}
\end{document}
Because of the enlarge top by
, the eyes don't overlap the text above the frogbox. Remove the enlarge top by
, and the eyes do overlap the text above the frogbox.
That all said, is there an alternative to overlay
that will account for potentially increased size of the frame+nodes? Is there an easier way to manage this than examining every node that might be added [it's not a static list for every frame of this type, they're markers regarding meta information] to see if the space allocated for the frame needs to be increased?
I could simply assume the new nodes will be present and allocate space for them, and it does look kind of nice to see the frames aligning at the top of the page whether the extra nodes are present or not (my current strategy), but I'd like to explore a more sophisticated presentation, where the extra space is present or not depending on whether the nodes are present. What's an easy way to do this?
mdframed
, which does what you want, totcolorbox
, which (possibly) does not?mdframed
does what I want, as far as this point is concerned, andtcolorbox
seems to offer capabilities I don't have inmdframed
. I thought I'd give it a try.tcolorbox
takes some efforts to replace the bounding box tracking oftikz
by its own mechanism. For your intended use, one would need to reset this to thetikz
tracking. Today, I do not have the time to investigate this matter further, but I will try another day.