# Putting a rectangle around matrix nodes?

I built up a simple UML diagram, where one of the class boxes has an union containing a number of elements. I want to show that those elements are part of an union.

But how can I do so with tikz? I tried to use a matrix, but it complains that I cannot nest matrices.

\documentclass[a4paper,12pt]{scrreprt}
\usepackage[utf8x]{inputenc}

\usepackage{tikz}
\usetikzlibrary{matrix,positioning,calc,arrows,shapes}

\tikzstyle{class}=[matrix of nodes, draw=black, font=\ttfamily\small]

\begin{document}

\begin{tikzpicture}[node distance=2cm]
\matrix (value) [class] {
\textbf{Value} \\
\hline
TypeA m\_type \\
\textit{Union:} \\ % TODO: want to have a rectangle around the next 6 entries!
TypeB int64Val\\
TypeC float64Val\\
TypeD stringVal\\
TypeE *funcVal\\
TypeF varsVal\\
};
\end{tikzpicture}

\end{document}

-
Please always provide an example that can be copy&pasted to compile (so it should in particular include all \tikzlibrary statements and not reference any nodes or styles not defined in the example). – Caramdir Feb 10 '11 at 16:24
@Caramdir done :) – Johannes Schaub - litb Feb 10 '11 at 16:41

\usetikzlibrary{calc}

[...]

\draw (value.north west) rectangle (value.south east);
\draw ($(value.north west)!(value-3-1.north west)!(value.south west) + (4pt,0)$) rectangle ($(value.south east) + (-4pt,4pt)$);


The first coordinate in the draw statement is the projection of (value-3-1.north west) (top left anchor the the first node in the third row) to the line between (value.north west) and (value.south west) and then shifting 4pt to the right.

-
Ohh great! I'm sorry for not mentioning that I have a frame around the "class" box too. I would like to have both the class frame and the union frame have some little space. Can I do that easily? – Johannes Schaub - litb Feb 10 '11 at 16:29
Hmm, maybe there is some "scale" utility or something, that scales the rectangle around its center? Ideally I would like to tell the "draw" command: "Draw the rectangle X pt smaller than the coordinates given". – Johannes Schaub - litb Feb 10 '11 at 16:35
@Johannes: See the updated answer – Caramdir Feb 10 '11 at 16:36
@Martin: That wouldn't just have pushed the inner box outward too in my original solution. – Caramdir Feb 10 '11 at 16:39
@Martin: I TikZ padding (=inner sep) is part of the width, in CSS I think it isn't (except in old IE versions). – Caramdir Feb 10 '11 at 17:10