1

I'd like to draw this as a TikZ:

  \
   \
    +---+---+
    | * | * |
    +/--+---\
    /        \
   1          +---+---+
              | * | * |
              +/--+---\
              /        \
             2          +---+---+
                        | * | * |
                        +/--+---+
                        /
                       3

I've tried various things to make an "empty rectangle with a dividing line, to no avail. . . .

1
  • 1
    use a node from shapes.multipart library
    – percusse
    Feb 26, 2016 at 2:09

1 Answer 1

2

Here's a simple example to get you started:

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{
  graphs,
  graphdrawing,
  shapes.multipart
}
\usegdlibrary{trees}

\tikzset{
  link/.style={
    rectangle split,
    rectangle split horizontal,
    rectangle split parts=2,
    draw,
    /tikz/graphs/as={\nodepart{two} \footnotesize\texttt{*ptr}},
  }
}

\begin{document}
\tikz \graph [tree layout] {
  head [draw, as=\emph{head}] -- {
     link1 [link] -- {
       1, 
       link2 [link] -- {
         2, 
         link3 [link] -- {
           3, 
           link4 [link]
         }
       }
     }
  }
};
\end{document}

output

3
  • This is great, and I've got it to work, but I do need the split left and right nodes---as in my ascii diagram. I was trying to hack texample.net/tikz/examples/tree.
    – 147pm
    Feb 26, 2016 at 2:45
  • @147pm I updated the answer to match more closely what you want (hopefully).
    – JP-Ellis
    Feb 26, 2016 at 6:58
  • Actually, I need the edge lines pointing to the number leaves to be directly under the first cell of the rectangle, not the second cell, otherwise the effect is lost. Also, when I removed the "*ptr" in the second cell, the edge lines went up into the rectangle. I need the lines to just touch the rectangles, not hike up into them. Sorry to make such demands, but I have no idea how to learn this on my own. Is there documentation somewhere? Being non-technical, I can't get much from man pages or reference dumps.
    – 147pm
    Feb 27, 2016 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.