[Tex/LaTex] Putting a rectangle around matrix nodes

matricestikz-pgf

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}   

Best Answer

\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.

result