-1

I have applied following answer for How should I draw a linked list each node pointed by additional node (I am using the exact code on the answer). But I was not able to manage to draw arrows in between cells.

I was wondering how could I draw arrows in between bottom cells:

Example:

enter image description here


Example for arrow passing on top of a inner arrow (assume there is a cell):

enter image description here


In case arrow exists from a cell that an another arrow already entered they overwrite on top of each other, is it possible shif them so they won't be drawn on top of each other while keeping same height for them.

enter image description here

with following code:

      \coordinate[below=of m-3-7](aux);
      \draw[->](m-5-7)--(aux)-|(m-5-5);
  \coordinate[below=of m-3-5](aux);
  \draw[->](m-5-5)--(aux)-|(m-5-3);

But I want lines not to overwrite on top of each other, example:

enter image description here

alper
  • 1,389
  • please have a look a the answer below -- add the following lines to your code at the end -- \coordinate[below=of m-4-1](aux); \draw[v2](m-4-1)--(aux)-|(m-4-3); -the first line creates a coordinate below the node 4 -- the second line draws the arrow down to the coordinate aux and then right to the node / -- the matrix auto names for the fourth row as follows -- m-4-1, m-4-2, m-4-3 – js bibra Jan 10 '21 at 15:34
  • make it below = 2cm-- or 3cm -- you can experiment to shift down or up – js bibra Jan 10 '21 at 16:53
  • Thanks what do you mean by shift down or up ? is it possible to shift right or left like its height will be same but arrow will be enter into right of the center and exit from left of the center of the cell – alper Jan 10 '21 at 17:10
  • please show a sketch of the desired output -- your question is not clear – js bibra Jan 10 '21 at 23:46
  • @jsbibra Thanks for your guide, I just want arrows not to overwrite on top of each other, please see an desire output sketch at bottom of my question – alper Jan 11 '21 at 10:47
  • please have a look at the new answer – js bibra Jan 11 '21 at 16:43
  • I have following code piece from the accepted answer (https://gist.github.com/avatar-lavventura/4abc57a82384793cd23950a32dec8b38) your solution does not work on this answer and Latex keep gives a compilation error not sure why as Package tikz Error: You need to say \usetikzlibrary{calc} for coordinate calculation. – alper Jan 12 '21 at 11:20
  • Should \draw[v2] be \draw[->]? – alper Jan 12 '21 at 11:45

1 Answers1

4

enter image description here

\documentclass[tikz,margin=3]{standalone}
\usepackage{sansmath}
\usetikzlibrary{fit,matrix,positioning,shadows, calc} 
\begin{document}
    \begin{tikzpicture}[font=\sffamily\sansmath,
        square/.style={minimum size=1cm,draw,fill=white,drop shadow},
        f/.style={fill=orange!20,draw=orange},
        v2/.style={-stealth,very thick,yellow!65!black}]
        \matrix[matrix of math nodes,row sep=-\pgflinewidth,column sep=1.5em,
        cells={nodes={square,
                text depth=0.25ex,text height=1em}},
        row 1/.style={nodes=f}] (m){
            0 & 4 & 10 \\[2em]
            -16 & -16 & -16\\
            3 & 10 & 15\\
            |[f]|4 & |[f]|10 & /\\
        };
        %
        \node[draw,dashed,inner sep=1em,fit=(m-1-1)(m-1-3)](f){};
        %
        \node[square,right=3em of m-1-3] (t){tail};
        %
        \foreach \x[count=\y] in {mapping,value,point,next}
        {\draw \ifnum\y=1 (f.west)
            \else
            (m-\y-1.west)\fi -- ++ (-2em,0) node[left]{\x};}
        %
        \draw[v2] (t) -- (m-1-3);
        \foreach \x in {1,2,3}
        {\draw[v2] (m-1-\x) -- (m-2-\x);}
    \coordinate[below=of m-4-1](aux);
    \draw[v2](m-4-1)--(aux)-|(m-4-3);
\end{tikzpicture}

\end{document}

changing the last two lines

\coordinate[below=of m-4-2](aux);
        \draw[v2](m-4-2)--(aux)-|(m-4-3);

will give

enter image description here

to place an additional node in the fourth row with arrow add the following code

\node[square,right=3em of m-4-3] (q){};
         \coordinate[below=1.5cm of m-4-1](auxx);
         \draw[v2](m-4-1)--(auxx)-|(q);

enter image description here

EDIT new answer

\documentclass[tikz,margin=3]{standalone}
\usepackage{sansmath}
\usetikzlibrary{fit,matrix,positioning,shadows, calc} 
\begin{document}
    \begin{tikzpicture}[font=\sffamily\sansmath,
        square/.style={minimum size=1cm,draw,fill=white,drop shadow},
        f/.style={fill=orange!20,draw=orange},
        v2/.style={-stealth,very thick,yellow!65!black}]
        \matrix[matrix of math nodes,row sep=-\pgflinewidth,column sep=1.5em,
        cells={nodes={square,
                text depth=0.25ex,text height=1em}},
        row 1/.style={nodes=f}] (m){
            0 & 4 & 10 \\[2em]
            -16 & -16 & -16\\
            3 & 10 & 15\\
            |[f]|4 & |[f]|10 & /\\
        };
        %
        \node[draw,dashed,inner sep=1em,fit=(m-1-1)(m-1-3)](f){};
        %
        \node[square,right=3em of m-1-3] (t){tail};
        %
        \foreach \x[count=\y] in {mapping,value,point,next}
        {\draw \ifnum\y=1 (f.west)
            \else
            (m-\y-1.west)\fi -- ++ (-2em,0) node[left]{\x};}
        %
        \draw[v2] (t) -- (m-1-3);
        \foreach \x in {1,2,3}
        {\draw[v2] (m-1-\x) -- (m-2-\x);}
    \coordinate[below=of m-4-1](aux);
    \draw[v2](m-4-1)--(aux)-|(m-4-3);

\drawv2--(m-4-2.west); \drawv2 -- ($(m-4-1.south)+(1ex,-3ex)$)-|($(m-4-2.south)$);

\drawv2 -- ($(m-4-2.south)+(1ex,-3ex)$)-|($(m-4-3.south)+(-2ex,0pt)$); \end{tikzpicture} \end{document}

enter image description here

js bibra
  • 21,280
  • On my end the arrow end is not shown and gives a compilation error. I was using @cis's solution where the latest code piece on his answer. I am also facing if an arrow exits from the same cell than another arrow entered , they on top of each other – alper Jan 10 '21 at 16:42
  • note that you can avoid overlap by using below = 1,5cm in the code \coordinate[below=1.5cm of m-4-1](auxx); -- this will shift the arrow down -- you can also use above, below right etc -- have a look at he tikz manual if possible – js bibra Jan 10 '21 at 16:52
  • instead of below is there right or left option? even below works still the arrow are drawn on top of each other, maybe sliding little bit to left/right – alper Jan 10 '21 at 16:56
  • 2
    Very nice and my compliments for your 10k. – Sebastiano Jan 10 '21 at 22:52
  • 2
    @Sebastiano thank you Sir, it is all because of your guidance and all other veterans of this site – js bibra Jan 10 '21 at 23:43
  • 2
    A nice suggestion. Don't follow me, I'm a very poor user. ahahahah. – Sebastiano Jan 10 '21 at 23:52