0

I'm having difficulty with trying to redraw the arrows from one node to another.

MWE:

\documentclass[a4paper, 11pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{pgfgantt}
\usepackage{geometry}

\geometry{ a4paper, total={170mm,257mm}, left=20mm, top=20mm, }

\usepackage{float} \usepackage{tikz} \usetikzlibrary{shapes.geometric, arrows, shadows} \usetikzlibrary{fit,backgrounds} \usetikzlibrary{shadows.blur} \begin{document}

\begin{center} \tikzset{ decision/.style={ diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt, drop shadow }, block/.style={ rectangle, draw, fill=blue!20, text width=7em, text centered, rounded corners, minimum height=2em, drop shadow }, line/.style={ draw, -latex' }, cloud/.style={ draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em, drop shadow }, rect/.style={ rectangle, rounded corners, minimum width=3.5cm, minimum height=1cm, text centered, draw=black, fill=blue!10,blur shadow }, arrow/.style={ thick,->,>=stealth } } \begin{tikzpicture}[node distance = 2cm, auto] % Place nodes

\node [cloud] (start) {Start};
\node [decision, below of=start] (newuser) {New User?};
\node [decision, below left=3cm of newuser] (christmassale) {Christams Sale?};
\node [decision, below right=3cm of newuser] (newcustomerthruref) {New Customer through Reference};
\node [decision, below left=2cm of christmassale] (firstorder)  {First Order?};     
\node [block, below left=1cm of firstorder] (discount15) {Total Discount +15\%};
\node [decision, below right=2cm and 1cm of discount15] (coupon) {Coupon?};  



\path [line] (start) -- (newuser);
\path [line] (newuser) -| (christmassale);
\path [line] (christmassale) -| (firstorder);
\path [line] (firstorder) -| (discount15);
\path [line] (discount15) |- (coupon);
\path [line] (discount15) |- (coupon);
\path [line] (christmassale) |- (coupon);
\path [line] (firstorder) -| (coupon);

% \draw [arrow] (discount15.east) |- ++(1.5cm,1.5cm) node[red] {$\bullet$} -| ([xshift=1cm]coupon.south);

\end{tikzpicture} \end{center} \end{document}

CURRENT OUTPUT:

enter image description here

IDEAL OUTPUT:

2 questions:

  • How do I change the vertical length of the paths/arrows (indicated in red) so that they're all uniform?
  • How do I draw the arrows leading [christmas sale] >> [coupon] && [first order] >> [coupon] as below? enter image description here

WHAT I TRIED:

I tried to play around with the following code but to no avail

\draw [arrow] (discount15.east) |- ++(1.5cm,1.5cm) node[red] {$\bullet$} -| ([xshift=1cm]coupon.south);
3kstc
  • 931
  • 6
  • 22
  • Your MWE is missing the positioning library. The length of vertical part is directly coupled to the vertical distance and the (vertical) size of the nodes. You place one nodes 3cm below left and another only 2cm. Of course, the lines will be different. Mixing diamonds and rectangles make it a bit harder to place nodes in a way that the vertical part will be exactly the same size with vanilla TikZ options. – Qrrbrbirlbel Feb 08 '23 at 13:13
  • For your second question, see Q102385. – Qrrbrbirlbel Feb 08 '23 at 13:14
  • Are you able to share an MWE? That'll give me a start... really struggling with the flowcharts – 3kstc Feb 08 '23 at 13:50

1 Answers1

2

There are a lot of different things happening in your diagram which are difficult to track:

The length of the vertical part of you connection is directly coupled to the vertical distance of the nodes as well as their vertical size.

To overcome this, we'll need to place the nodes a bit more automatic since a node distance without and is multipled by the square root of 2 and placed between the diagonal compass anchors. Even giving both node distances, vertical and horizontal gives unexpected results with the diamond shape.


In the colde below I define styles

  • below and left = of <ref> and
  • below and right = of <ref>

that act like below = of <ref>.center which places the north anchor of the new node in relation to the center anchor of the referenced node. This is what makes up the vertical length of your connections!

Furthermore, the nodes are shifted to the left or the right about the amount of the horizontal node distance. For this, I'm using the ext.positioning-plus library that provides the PGFMath function x_node_dist so that you only have to give the node distances once.


For connecting the nodes, I'll use the edge syntax because it makes it much easier to apply a common style for multiple connections.

The ext.paths.ortho provides

  • the path operation |-| and
  • ortho/install shortcuts that installs -| and |-| as to paths.

Furthermore, a negative ortho/distance is taken from (the border of) the target node to assure a common line to the last node. Here, I'm using a reference to y_node_dist via the ext.positioning-plus library.

The rdld (right, down, left, down) style finds a point to the right of christmassale but on the height of the starting node of the edge to assure the most complex connection to overlap. It also uses the x_node_dist to make sure the long vertical part of this connection is placed the same distance away from christmassale as are connections that exit the nodes on the left side.

Code

\documentclass[tikz, 11pt,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning, shadows.blur}
\usetikzlibrary{ext.positioning-plus, ext.paths.ortho, quotes}
\begin{document}
\begin{tikzpicture}[
  node distance = 2cm and 3cm,
  decision/.style = {
    diamond, draw, fill=blue!20, text width=4.5em, text badly centered,
    inner sep=0pt, drop shadow},
  block/.style = {
    rectangle, draw, fill=blue!20, text width=7em, text centered,
    rounded corners, minimum height=2em, drop shadow},
  line/.style  = -Latex,
  cloud/.style = {draw, ellipse, fill=red!20, minimum height=2em, drop shadow},
  below and left/.style ={below={#1.center}, xshift=-x_node_dist},
  below and right/.style={below={#1.center}, xshift= x_node_dist},
]

\node [cloud] (start) {Start}; \node [decision, below=of start] (newuser) {New User?}; \node [decision, below and left =of newuser] (christmassale) {Christmas Sale?}; \node [decision, below and right=of newuser] (newcustomerthruref) {New Customer through Reference}; \node [decision, below and left =of christmassale] (firstorder) {First Order?}; \node [block, below and left =of firstorder] (discount15) {Total Discount +15%}; \node [decision, below and right=of discount15] (coupon) {Coupon?};

\path[ line, near start, ortho/install shortcuts, % for -| and |-| ortho/distance=-.25*y_node_dist, rdld/.style={to path={ -- ([xshift=x_node_dist] christmassale|-\tikztostart)\tikztonodes |-| (\tikztotarget)}}] (start) edge (newuser) [-|] (newuser) edge[ "no"'] (christmassale) edge[ "yes"] (newcustomerthruref) (christmassale) edge[ "no"'] (firstorder) edge[rdld, "yes" midway] (coupon) (firstorder) edge[ "no"'] (discount15) edge[rdld, "yes" midway] (coupon) (discount15) edge[|-|] (coupon) ; \end{tikzpicture} \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821