Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Using \tikzmark may help. You may search this site for more details. –  Harish Kumar Apr 10 '12 at 2:19

1 Answer 1

up vote 2 down vote accepted

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.

enter image description here

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

Your Answer

 
discard

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.