4

Possible Duplicate:
Creating a node fitting the horizontal width of two other nodes

I would like to draw a hierarchy of boxes where the borders of the boxes are vertically in the same line of sight. To give an example: (Unfortunately, new members are not allowed to post images ...)

*----------------------------------*
|              Level 1             |
*----------------------------------*
*--------------*    *--------------*
|    Level 2   |    |    Level 2   |
*--------------*    *--------------*

My problem is that, using nodes and drawing rectangles, I can't figure out how to adjust the size of the level 1 box such that the right and left border are in the same line of sight as the boxes of level 2. Is it maybe the wrong approach? Thanks in advance!

Cheers, Sema

SeMa
  • 195
  • Welcome to TeX.sx! Can you provide a minimal working example (MWE) so that we can see what you accomplished so far? As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. – Qrrbrbirlbel Oct 12 '12 at 21:42

1 Answers1

2

A simple method when all widths are known.

The TikZ library positioning is used here. Now you can reference the outer points of a shape in below=of.

Code

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
    \draw [help lines] (-3,-2) grid (3,1);
    \node[
        minimum width=6cm,
        draw
        ] (l1) {Level 1};
    \node[
        below=of l1.west,
        anchor=west,
        minimum width=2.5cm,
        draw
        ] {Level 2a};
    \node[
        below=of l1.east,
        anchor=east,
        minimum width=2.5cm,
        draw
        ] {Level 2b};
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • 1
    Nearly the same code that I had prepared, so I prefer to don't post a nearly identical answer and vote for yours instead! ;-) – Benedikt Bauer Oct 12 '12 at 22:10