# Introducing a (sub)node within a part of a split rectangle (with tikz-pgf, for displaying memory data structures)

I'm trying to put a node (or, say, a chain) within one of the nodeparts of a split rectangle shape. So far I've been unable to make it work. Essentially I'm trying to represent a simple data structure on memory. It seems there are no ready-to-use libraries that support these so I've been using the split rectangle shape most of the time when it made sense.

\begin{tikzpicture}
\node (mysplitrectangle) [rectangle split, rectangle split parts=5,
draw, text width=3.75cm,
rounded corners]
{ %
\textbf{Nice split rectangle}
\nodepart{two}
\texttt{XYZ}
\nodepart{three}
XXX
\nodepart{four}
XXX
\nodepart{five}
\begin{tikzpicture}
\node (pewp) [draw] {foo};
\end{tikzpicture}
};
\end{tikzpicture}

-
Using \tikzmark may help. You may search this site for more details. – Harish Kumar Apr 10 '12 at 2:19

I am not exactly sure of the kind of diagram or chain you want to use, but a possible option is to use a box to store the chain and then use this box inside the multipart rectangle:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,chains}

\begin{document}

\newbox\boxa
\savebox\boxa{%
\begin{tikzpicture}[start chain=1 going right,
start chain=2 going below,
node distance=5mm,
every node/.style={draw,fill=blue!30}]
\node [on chain=1] {A};
\node [on chain=1] {B};
\node [on chain=1] {C};
\node [on chain=2] at (0.5,-.5) {0};
\node [on chain=2] {1};
\node [on chain=2] {2};
\node [on chain=1] {D};
\node [on chain=1] {E};
\node [on chain=1] {F};
\node [on chain=1] {G};
\end{tikzpicture}%
}

\begin{tikzpicture}
\node (mysplitrectangle) [rectangle split, rectangle split parts=5,
draw,rectangle split part align=left,
rounded corners]
{ %
\textbf{Nice split rectangle}
\nodepart{two}
\texttt{XYZ}
\nodepart{three}
XXX
\nodepart{four}
XXX
\nodepart{five}
\usebox\boxa
};
\node[xshift=5pt,anchor=west] at (mysplitrectangle.text east) {label1};
\node[xshift=5pt,anchor=west] at (mysplitrectangle.two east) {label2};
\node[xshift=5pt,anchor=west] at (mysplitrectangle.three east) {label3};
\node[xshift=5pt,anchor=west] at (mysplitrectangle.four east) {label4};
\node[xshift=5pt,anchor=west] at (mysplitrectangle.five east) {label5};
\end{tikzpicture}

\end{document}


To add labels you can use the anchors for the multipart rectangle (see page 453 of the pgf manual). The other problem mentioned in the comments (the contents overflowing to the right) is caused by the fixed width that you declared with text width=3,75; it can be solved either by increasing the value for text width, or not specifying a fixed value as I did in my modified example.

-
Nice, what would be the method to add labels to the right of the rectangle? aligned to each nodepart, that is. This is my last showstopper for now. :) – soze Apr 10 '12 at 3:04
Oh, and if it's possible to prevent the chain from overflowing the nodepart, preferably growing down once growing right implies overflow. – soze Apr 10 '12 at 3:06
@soze: please see my updated answer. – Gonzalo Medina Apr 10 '12 at 3:55
Thanks, works perfectly :) – soze Apr 11 '12 at 22:08