TikZ Nested Boxes – Creating Expandable Nested Boxes

boxesnestingtikz-pgf

Could someone please post a minimal tikz example to draw this:

nested boxes with tikz

I am currently doing this with nested tables, but would like to see how it can be done with tikz.

The nodes would ideally have a pre-set minimal width and height, yet expand with their contents.

Best Answer

The shapes.multipart library of TikZ can be helpful (refer to Section 48.6 Shapes with Multiple Text Parts of the pgfmanual); a little example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}

\begin{tikzpicture}[
  double/.style={draw, anchor=text, rectangle split,rectangle split parts=2},
  triple/.style={draw, anchor=text, rectangle split,rectangle split parts=3}
  ]
  \node[triple] {foo
    \nodepart{second}
      bar
    \nodepart{third}
      \tikz{\node[double] {\nodepart{second}baz};}
  };

  \node[triple] at (2.2,0) {some text here
    \nodepart{second}
      bar
    \nodepart{third}
      \tikz{\node[double] {\nodepart{second}some more text goes here};}
  };

  \node[double,align=center] at (7.5,0) {some text here
    \nodepart{second}
      bar \\
      \tikz{\node[double,align=center] {\nodepart{second}some more text\\ goes here};}
  };

\end{tikzpicture}

\end{document}