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 know how to create a multipart node in TikZ using \nodepart, and I know how I can draw lines from these nodeparts to hook them up to other nodes:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
    bnode/.style = {                                                     
        draw,
        rectangle split,
        rectangle split horizontal,
        rectangle split parts=4
    }
}
\begin{document}
\begin{tikzpicture}
\node[bnode]
   (root)
   {      \nodepart{one}
      $12$ \nodepart{two}
      $15$ \nodepart{three}
      $20$ \nodepart{four}
      $\times$};

\draw[->]
    (root.south west) -- +(-4,-1)
    node[bnode, anchor=north]
        (childnode)
        {      \nodepart{one}
            $3$ \nodepart{two}
            $9$ \nodepart{three}
            $10$ \nodepart{four}
            $12$};                           

\draw[->]
    (root.one split south) -- +(-2,-1)
    node[bnode, anchor=north]
        (childnode)
        {      \nodepart{one}
            $13$ \nodepart{two}
            $14$ \nodepart{three}
            $15$ \nodepart{four}
            $\times$};

\draw[->]
    (root.two split south) -- +(0,-1)
    node[bnode, anchor=north]
        (childnode)
        {      \nodepart{one}
            $17$ \nodepart{two}
            $18$ \nodepart{three}
            $\times$ \nodepart{four}
            $\times$};

\draw[->]
    (root.three split south) -- +(2,-1)
    node[bnode, anchor=north]
        (childnode)
        {      \nodepart{one}
            $21$ \nodepart{two}
            $29$ \nodepart{three}
            $\times$ \nodepart{four}
            $\times$};


\end{tikzpicture}
\end{document}

Renders:

enter image description here

Even in this simple example I had to calculate the correct location of the child nodes because they are overlapping. Imagine adding another level to the tree. These calculations would become very tedious.

I know TikZ has some nice tree syntax to easily draw trees, but I don't immediatly see how it applies here. Is there a way to use TikZ' child syntax to work with multipart nodes so that I don't have to worry about the spacing and location of their child nodes.

To clarify: every part of a multipart node should be able to have it's own child proper, and the children are multipart nodes themselves, which again can have multiple children (one for each nodepart).

share|improve this question

1 Answer 1

The probem stems from the fact that the a' is wider than just a. So, you can set the text width=1.0em, align=center which ensures that each of the nodes are of the same width:

enter image description here

Code:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
    bnode/.style = {   
        text width=1.0em, align=center,                                           
        draw,
        rectangle split,
        rectangle split horizontal,
        rectangle split parts=4
    }
}
\begin{document}
\begin{tikzpicture}
    \node[bnode]
       (root)
       {      \nodepart{one}
          $a$ \nodepart{two}
          $b$ \nodepart{three}
          $c$ \nodepart{four}
          $d$};

    \draw (root.one south) -- +(0,-1) node[draw, anchor=north](q) {$a'$};
    \draw (root.two south) -- +(0,-1) node[draw, anchor=north](q) {$b'$};
\end{tikzpicture}
\end{document}
share|improve this answer
    
Perhaps I wasn't clear enough about this. The a' and b' nodes are in reality themselves also multipart nodes, so they will be wider also. My question was: is there a way to automation the placing and connecting of these bushy tree structures. –  romeovs Jun 17 at 11:28
    
@romeovs: I'd suggest you update the question then and include code that shows the problem better. Not sure if there is a generic solution that will work in all cases, so if we have an actual example that reproduces the problem then perhaps a solution can be found that works for you. –  Peter Grill Jun 17 at 19:46
    
yes I elaborated the MWE! –  romeovs Jun 18 at 7:58

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.