This isn’t the first time this question was asked but the other solutions don’t work in my case.
Consider the following image:
It was created using this code:
\begin{tikzpicture}[
node distance=7mm,
title/.style={font=\fontsize{6}{6}\color{black!50}\ttfamily},
typetag/.style={rectangle, draw=black!50, font=\scriptsize\ttfamily}
]
\node (decomp) [title] { Decomposition };
\draw [draw=black!50] (decomp.north west) rectangle +(2.8cm, -2.7cm);
\node (di) [typetag, below=of decomp.west, anchor=west, xshift=2mm] { Independent };
\node (dr) [typetag, below=of di.west, anchor=west] { Reduction };
\node (dnc) [typetag, below=of dr.west, anchor=west] { DivideAndConquer };
\node (dep) at (3cm, 0) [title] { Dependency };
\draw [draw=black!50] (dep.north west) rectangle ($(dep.north east) - (0, 2cm)$);
\node (da) [typetag, below=of dep.west, anchor=west, xshift=2mm] { Atomic };
\node (dr) [typetag, below=of da.west, anchor=west] { Range };
\end{tikzpicture}
Needless to say, this code is horribly complicated and has no automation (for example, the width of the borders isn’t auto-computed to fit all elements, but rather put in by hand via painstaking trial and error).
There must be an easier way to achieve this.
In particular, I have two questions:
- How do I automate the drawing of the border + title (the grey text) so that the border is just large enough to accomodate all the
typetag
elements that follow after (and how to specify them?) - How can I arrange the
typetag
elements more smartly? (having to write, every time,below=of Element.west, anchor=west
is extremely annoying, but I don’t succeed to put this into thetypetag/.style
because TikZ “forgets” this information (I have also tried addingever node/.style={anchor=west}
in thetikzpicture
options, to no avail).
Question 1 is the important thing here, though. Question 2 is more of a general question that crops up again and again …
Best Answer
For the first point, you can use the
fit
library.For the second: According to the manual, setting
below
also setsanchor=north
. So addinganchor=west
totypetag
and then settingtypetag
afterbelow
does the trick.(
inner sep
, should probably be adjusted a bit)