2

I want to draw dashed arrows (|-) starting from splitted rectangle rows into a node located bottom right.

I observe that multiple dashed lines may draw on top of each other to draw a straight line. Even I manage to achieve what I want when I shift initial rectangle-node all the arrows messed up I have to re-arrange their locations since I embedded their grid positions in my approach.

my code:

\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{
    chains,
    positioning,
    shapes.geometric,
    shapes
}
\begin{document}
\section{Example}
\noindent
\begin{tikzpicture}[
        node distance = 4mm and 8mm,
        arr/.style = {-Stealth, semithick},
        C/.style = {circle, draw, font=\footnotesize},
        N/.style = {draw, very thick,
                font=\small, align=left,
                inner sep=5pt},
        data/.style={
                draw,
                rectangle split,
                rectangle split parts=4,
                text centered,
                font=\scriptsize
            }
    ]
    \node [data,label=below:{test}] (n1) at (1,1) {
            one
            \nodepart{second} two
            \nodepart{third} three
            \nodepart{fourth} four
        };

    \node[
        cylinder,draw,
        shape border rotate=90,
        semithick,
        fill=white,
        shape aspect=0.2,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=1pt,
        align=center,
        below = of n1,
        xshift=18mm,
    ] (n2) {Storage};
    %
    \draw[dashed,semithick] (n1.one east) -| (1.65 ,0) |- (n2.west);
    \draw[dashed,semithick] (n1.40) -| (1.65 ,0) |- (n2.west);
    \draw[dashed,semithick] (n1.three east) -| (1.65 ,0) |- (n2.west);
\end{tikzpicture}
\end{document}

output:

enter image description here

wanted output:

enter image description here

as:

(*)--
(*)--|
(*)--|
(*)  |
     |--->(*)
3
  • Why you not provide MWE? Code fragment require, that we need to construct document preamble, which you already have (and not share with us...)
    – Zarko
    Jul 20, 2022 at 12:36
  • No, you provide only code fragment. Missed is document preamble, where are documentclass, loaded packages and needed libraries ...
    – Zarko
    Jul 20, 2022 at 12:41
  • Ah my mistake!! I copied not complete section from emacs. Updated
    – alper
    Jul 20, 2022 at 12:42

2 Answers 2

4

I would write all style definition into tikzpicture options (that MWE is more consistent), define aux coordinate for drawing connection lines in a loop and use relative node positioning.

\documentclass[5p,times]{elsarticle}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                shapes.geometric, shapes.multipart
                }

\begin{document}
\section{Example}
\noindent%
    \begin{tikzpicture}[
node distance = 4mm and 8mm,
  data/.style = {rectangle split, rectangle split parts=4,
                 draw, semithick, font=\small},
  disk/.style = {cylinder, draw, semithick,
                 shape border rotate=90,
                 shape aspect=0.2,
                 font=\small},
  line/.style = {densely dashed, semithick}
                       ]
\node [data, 
       label=below:{test}] (n1) {one
                                \nodepart{second} two
                                \nodepart{third} three
                                \nodepart{fourth} four
                                };
\coordinate[right=of n1.one east]   (aux);
\node[disk, 
      below right = of n1.south -| aux] (n2) {Storage};
%
    \foreach \x in {one , two , three }
\draw[line] (n1.\x east) -- (aux |- n1.\x east); 
\draw[line] (aux) |- (n2.west);
    \end{tikzpicture}
\end{document}

enter image description here

3
  • Can we coordinate aux as ex: 5mm right of a node?
    – alper
    Jul 21, 2022 at 1:01
  • @alper, just try. An if your idea will not work, investigate, why not:-). If I correct understand you, you like to have different distance from between data node and aux coordinate and from aux to ``disk node. If this is the case, than replace \coordinate[right=of n1.one east] (aux); with \coordinate[right=5mm of n1.one east] (aux);
    – Zarko
    Jul 21, 2022 at 1:55
  • I keep trying :-) but I feel like I am trying to play piano without able to read musical notes, see what works and stick to it. But always I feel like I am doing and learning something wrong that I won’t be able to re-learn it. You got my question right thanks for the replace string. First I applied \coordinate[right=of n5,xshift=-6.1mm] (aux); but I think I can use more clean approach just like \coordinate[right=5mm of n1.one east] (aux);
    – alper
    Jul 21, 2022 at 8:35
2

You should only draw every path segment once. That is, draw one line that goes all the way from start to end and then draw only the connecting parts of the other lines:

\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{
    chains,
    positioning,
    shapes.geometric,
    shapes
}
\begin{document}
\section{Example}
\noindent
\begin{tikzpicture}[
        node distance = 4mm and 8mm,
        arr/.style = {-Stealth, semithick},
        C/.style = {circle, draw, font=\footnotesize},
        N/.style = {draw, very thick,
                font=\small, align=left,
                inner sep=5pt},
        data/.style={
                draw,
                rectangle split,
                rectangle split parts=4,
                text centered,
                font=\scriptsize
            }
    ]
    \node [data,label=below:{test}] (n1) at (1,1) {
            one
            \nodepart{second} two
            \nodepart{third} three
            \nodepart{fourth} four
        };

    \node[
        cylinder,draw,
        shape border rotate=90,
        semithick,
        fill=white,
        shape aspect=0.2,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=1pt,
        align=center,
        below = of n1,
        xshift=18mm,
    ] (n2) {Storage};

    \draw[dashed,semithick] (n1.one east) -| (1.65,0) |- (n2.west);
    \draw[dashed,semithick] (n1.two east) -- (n1.two east -| 1.65,0);
    \draw[dashed,semithick] (n1.three east) -- (n1.three east -| 1.65,0);
\end{tikzpicture}
\end{document}

enter image description here

Alternative approach: Draw the part where all three lines overlap first. That is, start from the coordinate where all three lines meet:

\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.one east);
\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.two east);
\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.three east);
4
  • Do you advice drawing using -- +(3mm,0); instead of using grid coordinates , like when we shift the rectange to (2,0) the dashed lines misaligned
    – alper
    Jul 20, 2022 at 12:55
  • Sure, this can be helpful. You can then just do \draw[dashed,semithick] (n1.one east) -| +(.5,0) |- (n2.west); and \draw[dashed,semithick] (n1.two east) -- +(.5,0);. Jul 20, 2022 at 13:00
  • 1
    for the n1.three east , same approach as well? I like the alternative approach you provided , dashed lines won't overlay each other on that right?
    – alper
    Jul 20, 2022 at 13:06
  • Yes, same for n1.three east. In the alternative approach, the part where the lines overlap is drawn three times, but since all three lines start at the same coordinate, the dash pattern won't shift. Jul 20, 2022 at 13:09

You must log in to answer this question.

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