Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
"The nodes would ideally have a pre-set minimal width and height, yet expand with their contents." That is the standard behaviour of nodes, isn't it? –  Seamus May 19 '11 at 13:53
    
@Seamus: Normally the minimal width and height is zero IIRC. The expanding part is standard behaviour. –  Martin Scharrer May 19 '11 at 14:52
    
@Martin right, but minimum height and minimum width are keys tikz recognises... –  Seamus May 19 '11 at 15:49
add comment

2 Answers

up vote 12 down vote accepted

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}

share|improve this answer
    
Lovely, thank you! How would I go about breaking text though? some more \\ text goes here just removes the space between more and text. –  Nickolay Kolev May 19 '11 at 14:29
    
@Nickolay Kolev: you can use the align= key for the nodes; I've updated my example. –  Gonzalo Medina May 19 '11 at 14:36
add comment

Do you know about the drs package? (I assuming you want to construct discourse representation structures and tikz itself isn't a requirement.)

\documentclass{article}
\usepackage{drs}
\begin{document}
\drs{X}{ the lawyers(X) \\ 
   \qdrs{x}{x $\in$ X}
        {every}{x} 
        {y}{secretary(y) \\ x hired y}}
\end{document}

enter image description here

share|improve this answer
    
I do know it, and it is what I am using right now. I am having a few issues with it though, and I wanted to learn TikZ anyway, so I thought of writing a replacement. –  Nickolay Kolev May 20 '11 at 7:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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