4

I'm struggling to force the arrow to connect on a specific side of a node. I'm interested in accomplishing either solution:

  • Explicitly forcing arrow to connect to the left hand side of the node
  • Make of us of automated positioning / alignment to force arrow to not overlap with other arrows

Examples

Present Results

Present result

Desired outcome

The arrow travels above the bottom nodes and enters the BigProcess node so it does not cross with the remaining arrows. desired arrow direction

MWE

% vim:ft=tex:
%
\documentclass{standalone}

% TiKz drawing \usepackage{tikz} \usetikzlibrary{ matrix, arrows.meta, positioning, scopes, backgrounds, fit}

\begin{document} % Define set to use across flow charts \tikzset{% >={Latex[width=2mm,length=2mm]}, % Specifications for style of nodes: base/.style = {rectangle, rounded corners, draw=black, minimum width=2cm, minimum height=1cm, text centered, font=\sffamily}, activityStarts/.style = {base, fill=blue!30}, startstop/.style = {base, fill=red!30}, activityRuns/.style = {base, fill=green!30}, process/.style = {base, minimum width=2.5cm, fill=orange!15, font=\ttfamily}, back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt} }

\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
    % Specification of nodes (position, etc.)
    \node (start) [activityStarts] {Start Node};    
    \node (lit) [process, right = of start] {ProcNode};
    \node (data) [process, right = of lit] {ProcTwo};
    \node (eda) [process, right = of data] {ProcThree};
    \node (reseldev) [activityRuns, below = 4cm of start] {BigProcess}; 
    \node (res2) [process, right = of reseldev] {Res 2};
    \node (res1) [process, above = of res2] {Res 1};
    \node (res3) [process, below = of res2] {Res 3};
    \draw [->] (start) -- (lit);
    \draw [->] (lit) -- (data);
    \draw [->] (data) -- (eda);
    \draw [->, rounded corners=5pt] (eda) -- ++ (0,0) |-  (reseldev);
    \draw [->] (reseldev) -- (res1);
    \draw [->] (reseldev) -- (res2);
    \draw [->] (reseldev) -- (res3);
\end{tikzpicture}


\end{document}

Konrad
  • 279
  • 3
  • 12
  • You can't make it automatically avoid crossing what's already there without something like the graphs layout stuff or forest. You can easily force the connection to wherever you want on the node's border. But there's no automatic routing option. Alan's answer is probably the closest to automagical short of special cases such as graphs/trees. – cfr Jul 31 '23 at 05:08
  • This Q remind me of Q546765 but for a simple well structured diagram like this it's probably too much. – Qrrbrbirlbel Jul 31 '23 at 09:16

3 Answers3

7

You can use the ext.paths.ortho library (part of the tikz-extra set of libraries) to make the zig-zag connection as follows:

% vim:ft=tex:
%
\documentclass{standalone}

% TiKz drawing \usepackage{tikz} \usetikzlibrary{ matrix, arrows.meta, positioning, scopes, backgrounds, fit, ext.paths.ortho}

\begin{document} % Define set to use across flow charts \tikzset{% >={Latex[width=2mm,length=2mm]}, % Specifications for style of nodes: base/.style = {rectangle, rounded corners, draw=black, minimum width=2cm, minimum height=1cm, text centered, font=\sffamily}, activityStarts/.style = {base, fill=blue!30}, startstop/.style = {base, fill=red!30}, activityRuns/.style = {base, fill=green!30}, process/.style = {base, minimum width=2.5cm, fill=orange!15, font=\ttfamily}, back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt} }

\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
    % Specification of nodes (position, etc.)
    \node (start) [activityStarts] {Start Node};    
    \node (lit) [process, right = of start] {ProcNode};
    \node (data) [process, right = of lit] {ProcTwo};
    \node (eda) [process, right = of data] {ProcThree};
    \node (reseldev) [activityRuns, below = 4cm of start] {BigProcess}; 
    \node (res2) [process, right = of reseldev] {Res 2};
    \node (res1) [process, above = of res2] {Res 1};
    \node (res3) [process, below = of res2] {Res 3};
    \draw [->] (start) -- (lit);
    \draw [->] (lit) -- (data);
    \draw [->] (data) -- (eda);
    \draw [->, rounded corners=5pt] (eda.south) |-|[ distance=.75cm]  (reseldev.north);
    \draw [->] (reseldev) -- (res1);
    \draw [->] (reseldev) -- (res2);
    \draw [->] (reseldev) -- (res3);
\end{tikzpicture}


\end{document}

output of code

Alan Munn
  • 218,180
4

A wee bit modified nice @Alan Munn answer (+1), mostly off-topic suggestions:

  • use of the chains library for positioning nodes
  • use of common node style (P) for all nodes
  • use loop for drawing arrows between reseldev and res... nodes
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                ext.paths.ortho,
                positioning,
                }

\begin{document} \begin{tikzpicture}[ node distance=8mm and 12 mm, arr/.style = {-{Latex[width=2mm,length=2mm]}}, base/.style = {rectangle, rounded corners, draw=, minimum width=2cm, minimum height=1cm, font=\sffamily}, P/.style = {base, fill=#1}, ] % Specification of nodes (position, etc.) \begin{scope}[start chain = going right, nodes = {P=red!30,on chain, join=by arr}] \node (start) [P=blue!30] {Start Node}; \node (lit) {ProcNode}; \node (data) {ProcTwo}; \node (eda) {ProcThree}; \end{scope} \begin{scope}[start chain = going below, nodes = {P=red!30,on chain}] \node (res1) [below=of lit] {Res 1}; \node (res2) {Res 2}; \node (res3) {Res 3}; \end{scope} % \node (reseldev) [P=green!30, left=of res2] {BigProcess}; % arrows out of join macro \foreach \i in {res1, res2, res3} \draw[arr] (reseldev) -- (\i.west);

\draw [->, rounded corners] (eda) |-|[ distance=4mm] (reseldev); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517
3

Try this modified (partially) code:

\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
        % Specification of nodes (position, etc.)
        \draw[gray!20] (0,0) grid (12,-8);% You can comment or delete this line
        \node (start) [activityStarts] {Start Node};    
        \node (lit) [process, right = of start] {ProcNode};
        \node (data) [process, right = of lit] {ProcTwo};
        \node (eda) [process, right = of data] {ProcThree};
        \node (reseldev) [activityRuns, below = 4cm of start] {BigProcess}; 
        \node (res2) [process, right = of reseldev] {Res 2};
        \node (res1) [process, above = of res2] {Res 1};
        \node (res3) [process, below = of res2] {Res 3};
        \draw [->] (start) -- (lit);
        \draw [->] (lit) -- (data);
        \draw [->] (data) -- (eda);
    %   \draw [->, rounded corners=5pt] (eda) -- ++ (0,0) |-  (reseldev);
        \draw [->] (reseldev) -- (res1);
        \draw [->] (reseldev) -- (res2);
        \draw [->] (reseldev) -- (res3);
        \draw[->] (eda.270)--(11.8,-1)--(0,-1)-- (reseldev);% <<< added
    \end{tikzpicture}

Output:

enter image description here

In any case I think this solution is more direct:

enter image description here

with this modified final code:

% vim:ft=tex:
\documentclass[border=10pt]{standalone}

% TiKz drawing \usepackage{tikz} \usetikzlibrary{ matrix, arrows.meta, positioning, scopes, backgrounds, fit}

\begin{document} % Define set to use across flow charts \tikzset{% >={Latex[width=2mm,length=2mm]}, % Specifications for style of nodes: base/.style = {rectangle, rounded corners, draw=black, minimum width=2cm, minimum height=1cm, text centered, font=\sffamily}, activityStarts/.style = {base, fill=blue!30}, startstop/.style = {base, fill=red!30}, activityRuns/.style = {base, fill=green!30}, process/.style = {base, minimum width=2.5cm, fill=orange!15, font=\ttfamily}, back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt} }

\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
    % Specification of nodes (position, etc.)
    \node (start) [activityStarts] {Start Node};    
    \node (lit) [process, right = of start] {ProcNode};
    \node (data) [process, right = of lit] {ProcTwo};
    \node (eda) [process, right = of data]  {ProcThree};
    \node (reseldev) [activityRuns, below = 4cm of eda] {BigProcess}; 
    \node (res2) [process, left = of reseldev] {Res 2};
    \node (res1) [process, above = of res2] {Res 1};
    \node (res3) [process, below = of res2] {Res 3};
    \draw [-&gt;] (start) -- (lit);
    \draw [-&gt;] (lit) -- (data);
    \draw [-&gt;] (data) -- (eda);
    \draw [-&gt;] (reseldev) -- (res1);
    \draw [-&gt;] (reseldev) -- (res2);
    \draw [-&gt;] (reseldev) -- (res3);
    \draw[-&gt;] (eda)-- (reseldev);
\end{tikzpicture}

\end{document}