1

How can I make a similar visualization of data structures and indexes? I went through the documentation of TikZ and could not find a way.

enter image description here

2
  • 2
    I think the easiest way would be multipart nodes. See section 17.3 Multi-Part Nodes of the Tikz manual, page 222.
    – Alenanno
    Jun 21, 2015 at 18:58
  • I'd rather use Graphviz and its record shape. You can combine this with tikz using dot2tex. The bonus of Graphviz is that you do not have to care about the shape of the arrows but they are layed out automatically without crossing the nodes.
    – m.s.
    Jun 21, 2015 at 19:12

1 Answer 1

5

Here's a starting point for you using Multipart nodes. Feel free to ask if something is not clear.

Output

figure 1

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, arrows.meta}

\tikzset{
    every node/.style={draw, text height=1.5ex},
    split/.style={rectangle split, rectangle split parts=#1,draw,
        rectangle split horizontal=false,rectangle split part align=base},
}
\begin{document}
\begin{tikzpicture}[->, -{Latex}]

\node[split=2] (a1) at (0,0) {0x10ba8};
\node[split=4] (a2) at (4,1) {0xf7fc4380\nodepart{four}-1};
\node[split=4] (a3) at (4,-1) {0xf7fc44b8\nodepart{four}2};

\node[split=4] (a4) at (8,-3) {(nil)\nodepart{four}-1};

\draw (a1) -- (a2);
\draw (a1) -- (a3);

\path (a2.east) edge[out=-35,in=135] (a4.north west);

\end{tikzpicture}
\end{document}
4
  • Is there a way to draw a path/arrow from a certain row to a certain row?
    – zvisofer
    Jun 21, 2015 at 20:38
  • 1
    @zvisofer Yes. For example, (a2.three east) where "three" is the third part of the a2 node.
    – Alenanno
    Jun 21, 2015 at 20:52
  • is it possible to add a label to an adge/path?
    – zvisofer
    Jun 22, 2015 at 17:06
  • @zvisofer Yes. Add to the path (you can add this right before the ;), node[midway] {}. midway will put it in the middle. pos= will put it at a certain point from 0 to 1 (decimals), therefore midway = pos=.5. You can also add left, right, above, etc and anchor=... like any node.
    – Alenanno
    Jun 22, 2015 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .