4

I will draw a graph representation as adjacency array, also something like that:

example

How to make it? I didn't found any examples like the picture above.

Max
  • 638
  • 2
    This could help: http://www.texample.net/tikz/examples/feature/chains/ – Sigur Feb 18 '15 at 16:33
  • 2
    With the exception of the squiggly line pointing to Cell X, these are all fairly standard Tikz elements. Start with the section on matrices. – John Kormylo Feb 18 '15 at 16:38

1 Answers1

9

A starting point:

enter image description here

The code:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,arrows.meta,arrows}

\tikzset{
mymat/.style={
  matrix of math nodes,
  text height=2.5ex,
  text depth=0.75ex,
  text width=3.25ex,
  align=center,
  column sep=-\pgflinewidth
  },
mymats/.style={
  mymat,
  nodes={draw,fill=#1}
  }  
}
\begin{document}

\begin{tikzpicture}[>=latex]
\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,0) 
(mat1)
{
0 & 1 & 2 & 3 & 4 \\
2 & 1 & 3 & 2 & 1 \\
};
\matrix[mymat,right=of mat1,row 2/.style={nodes={draw,fill=gray!30}}]
(mat2)
{
5 & 6 & 7 & 8 \\
2 & 1 & 2 & 1 \\
};
\matrix[mymats=white,anchor=west]
at (0,-2) 
(mat3)
{
1 & 2 & 0 & 0 & 3 & ? & 2 & 4 & 3 \\
};
\matrix[mymats=gray!30,right=of mat3]
(mat4)
{
? & 6 & 7 & 5 & 8 & 7 & ? \\
};

\node[above=0pt of mat1]
  (cella) {Cell A};
\node[above=0pt of mat2]
  (cellb) {Cell B};
\node at (mat4-1-7.north|-cellb)
  (cellx) {Cell X};

\begin{scope}[shorten <= -2pt]
\draw[*->]
  (mat1-2-1.south) -- (mat3-1-1.north);
\draw[*->]
  (mat1-2-2.south) -- (mat3-1-3.north);
\draw[*->]
  (mat1-2-3.south) -- (mat3-1-4.north);
\draw[*->]
  (mat1-2-4.south) -- (mat3-1-7.north);
\draw[*->]
  (mat1-2-5.south) -- (mat3-1-9.north);

\draw[*->]
  (mat2-2-1.south) -- (mat4-1-1.north);
\draw[*->]
  (mat2-2-2.south) -- (mat4-1-3.north);
\draw[*->]
  (mat2-2-3.south) -- (mat4-1-4.north);
\draw[*->]
  (mat2-2-4.south) -- (mat4-1-6.north);

\draw[*->,dashed,line width=0.7pt]
  (mat4-1-1.north) to[out=90,in=-60,looseness=0.4] (mat1-2-3.south);
\draw[*->,dashed,line width=0.7pt]
  (mat3-1-6.north) to[out=90,in=-90] (mat2-2-1.south);
\draw[*->,dashed,line width=0.7pt]
  (mat4-1-7.north) ..
    controls ++ (0.5,0.5) and ++(-1,-0.7) ..  
  (cellx.south);
\end{scope}
\end{tikzpicture}

\end{document}
Gonzalo Medina
  • 505,128
  • On my question's (https://tex.stackexchange.com/questions/586027/how-to-draw-a-list-that-its-items-point-to-a-structure) comment section I am adviced to your answer. On your answer, is it easy task to transform all arrays into vertical format? – alper Apr 05 '21 at 19:19
  • how can I reduce size of the bullet? – alper Oct 06 '22 at 10:44