TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.



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


\begin{tikzpicture}[node distance=2cm]
    \matrix (value) [class] {
        \textbf{Value} \\
        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\\

share|improve this question
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
up vote 2 down vote accepted


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


share|improve this answer
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

Your Answer


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.