2

Trying to draw an adjacency list (see attachment). Any advise ?enter image description here

  • Have a look at any of these: https://tex.stackexchange.com/questions/288362/doubly-linked-list-tikz https://tex.stackexchange.com/questions/86766/array-of-linked-lists-like-in-data-structure https://tex.stackexchange.com/questions/394432/how-to-draw-circular-linked-list https://tex.stackexchange.com/questions/296022/drawing-a-linked-list-as-a-tree Those are about linked lists but the concept for drawing those is the same. – Henri Menke May 02 '18 at 06:18
  • Also very related, maybe even duplicate: https://tex.stackexchange.com/questions/228835/how-to-draw-adjacency-array-with-tikz – Henri Menke May 02 '18 at 06:20

2 Answers2

3

Do you need TikZ for this ?

\documentclass[varwidth,border=7pt]{standalone}
\begin{document}
    $\fbox{x}\rightarrow\fbox{x}\fbox{x}\fbox{x}\fbox{x}$
\end{document}

enter image description here

Kpym
  • 23,002
  • This solution breaks as soon as you have a list of characters with different depth and height. For example, the following will look jagged: $\fbox{x}\rightarrow\fbox{x}\fbox{q}\fbox{t}$ – Janez Kuhar Jun 04 '21 at 09:08
  • @JanezKuhar Not very hard to adapt, using \strut or \vphantom, like in $\fbox{x\strut}\rightarrow\fbox{x\strut}\fbox{q\strut}\fbox{t\strut}$. – Kpym Jun 05 '21 at 10:11
2

enter image description here

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=latex,x=1.0cm,y=1.0cm]
\fill[line width=2.pt,color=black,fill=white] (0.,0.) -- (1.,0.) -- (1.,1.) -- (0.,1.) -- cycle;
\fill[line width=2.pt,color=black,fill=white] (2.,1.) -- (2.,0.) -- (3.,0.) -- (3.,1.) -- cycle;
\fill[line width=2.pt,color=black,fill=white] (4.,1.) -- (3.,1.) -- (3.,0.) -- (4.,0.) -- cycle;
\fill[line width=2.pt,color=black,fill=white] (4.,1.) -- (4.,0.) -- (5.,0.) -- (5.,1.) -- cycle;
\draw [line width=2.pt,color=black] (0.,0.)-- (1.,0.);
\draw [line width=2.pt,color=black] (1.,0.)-- (1.,1.);
\draw [line width=2.pt,color=black] (1.,1.)-- (0.,1.);
\draw [line width=2.pt,color=black] (0.,1.)-- (0.,0.);
\draw [line width=2.pt,color=black] (2.,1.)-- (2.,0.);
\draw [line width=2.pt,color=black] (2.,0.)-- (3.,0.);
\draw [line width=2.pt,color=black] (3.,0.)-- (3.,1.);
\draw [line width=2.pt,color=black] (3.,1.)-- (2.,1.);
\draw [line width=2.pt,color=black] (4.,1.)-- (3.,1.);
\draw [line width=2.pt,color=black] (3.,0.)-- (4.,0.);
\draw [line width=2.pt,color=black] (4.,0.)-- (4.,1.);
\draw [line width=2.pt,color=black] (4.,0.)-- (5.,0.);
\draw [line width=2.pt,color=black] (5.,0.)-- (5.,1.);
\draw [line width=2.pt,color=black] (5.,1.)-- (4.,1.);
\draw [->,line width=2.pt] (1.,0.5) -- (2.,0.5);
\draw (0.25,.7) node[anchor=north west] {$X$};
\draw (2.25,.7) node[anchor=north west] {$X$};
\draw (3.25,.7) node[anchor=north west] {$X$};
\draw (4.25,.7) node[anchor=north west] {$X$};
\end{tikzpicture}
\end{document}
Sebastiano
  • 54,118