I want to draw the image given below. I am able to draw array with some arrows but not able to draw the exact image.

enter image description here

See my code:


\usetikzlibrary{positioning,matrix, arrows.meta}

\date{February 2018}


\matrix (A) [ampersand replacement=\&,matrix of nodes, nodes={draw, minimum size=8mm},
    column sep=-\pgflinewidth]{
    3 \& 4 \& 4 \& 1 \& 4 \& 1 \& 2 \& 3\\};
\foreach \i [evaluate=\i as \ni using {int(\i)},
                evaluate=\i as \ntext using {int(\i-1)}] in {1,3,4,6} 
    \draw [{Stealth}-, red!70] (A-1-\ni.south west)--++(-90:5mm) node[below] {\ntext};


complied output:

enter image description here

Question : How to draw the image with tikz?

  • Please edit your question to indent the code portion. Or use the {} button
    – Thruston
    Feb 1, 2018 at 14:07
  • And what is that actual question? Which bit are you stuck on?
    – Thruston
    Feb 1, 2018 at 14:08

1 Answer 1


i understood, that you like with your code obtain the showed image:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}

    node distance = 21mm and 7mm,
    box/.style = {draw, minimum size=6mm, inner sep=0pt, outer sep=0pt, anchor=center},
      pin edge = {Straight Barb-, shorten <=1mm,semithick}
\matrix (m) [matrix of nodes,
             column sep=-\pgflinewidth,
             inner sep=0pt,
  1 & 2 & 3 &  \quad$\dotsm$\quad\vphantom{4}  & k     \\
\node (h2) [box,below=of m-1-2] {2};
\node (h1) [box, left=of h2,
            pin=240:head]       {1};
\node (h3) [box,right=of h2]    {3};
\node (hk) [box,below right=of m-1-5] {$k$};
\draw[dashed,-Straight Barb, shorten <=1mm, shorten >=1mm]
    (m-1-1.south) edge [bend right]   (h1.north)
    (h1.north)    edge [bend right]   (m-1-1.south)
    (m-1-2.south) edge [bend right]   (h2.north)
    (h2.north)    edge [bend right]   (m-1-2.south)
    (m-1-3.south) edge [bend right]   (h3.north)
    (h3.north)    edge [bend right]   (m-1-3.south)
    (m-1-5.south) edge [bend right]   (hk.north)
    (hk.north)     to  [bend right]   (m-1-5.south);
\draw[-Straight Barb, transform canvas={yshift= 1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
\draw[Straight Barb-, transform canvas={yshift=-1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
\draw[loosely dotted, ultra thick, shorten <=3mm, shorten >=3mm]
    (h3) -- (hk);

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.