The flowchart is almost what I want, but I am having a problem getting the arrow head to point in the correct direction in one of the paths that has turns in it. The picture shows the problem, and the code I used to generated looks good, it just doesn't work.
What am I doing wrong, and how can I fix it? I want to really understand the fix and not just fix this one flowchart, since I have to typeset many flowcharts for a manual.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,arrows.meta}
\tikzstyle{startstop} = [draw, rounded rectangle, text centered, draw=black,thick]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, text centered]
\tikzstyle{process} = [rectangle, text centered, draw=black,thick]
\tikzstyle{decision} = [diamond, text centered, draw=black,thick]
\tikzstyle{arrow} = [-{Stealth[scale=1.2]},rounded corners,thick]
\begin{document}
\begin{tikzpicture}
\node (start) [startstop] {Start};
\node (io1) [io,below=0.5 of start] {Read $R$};
\node (box1) [process,below=0.5 of io1] {$X \gets 0$};
\node (branch1) [decision,aspect=2,below=0.7 of box1] {$X > R-1$};
\node (return) [startstop,left=1 of branch1] {Return};
\node (box2) [process,below=0.7 of branch1] {$C \gets 0$};
\node (branch2) [decision,below=0.7 of box2] {$C > 2$};
\node (box3) [process,right=1 of branch2] {$X \gets X+1$};
\node (io2) [io,below=0.7 of branch2] {Read $A_{X,C}$};
\node (box4) [process,below=0.7 of io2] {$C \gets C+1$};
\draw [arrow] (start) -- (io1);
\draw [arrow] (io1) -- (box1);
\draw [arrow] (box1) -- coordinate[midway](m1)(branch1);
\draw [arrow] (branch1) -- coordinate[pos=0.4](m3)(box2);
\node [black,right=0.1 of m3] {False};
\draw [arrow] (branch1) -- coordinate[pos=0.4](m4)(return);
\node [black,above=0.1 of m4] {True};
\draw [arrow] (box2) -- coordinate[midway](m2)(branch2);
\draw [arrow] (branch2) -- coordinate[pos=0.4](m5)(io2);
\node [black,right=0.1 of m5] {False};
\draw [arrow] (branch2) -- coordinate[pos=0.4](m6)(box3);
\node [black,above=0.1 of m6] {True};
\draw [arrow] (io2) -- (box4);
\draw [arrow] (box4) |- ++(0,-1) -| ++(-2.5,0) |- ([xshift=-2.5]m2) -- (m2.west);
\draw [arrow] (box3) |- (m1);
\end{tikzpicture}
\end{document}
Best Answer
Instead of
use
Cause of wrong arrow direction is incorrect use of
|-
in arrow path.Upgrade: Complete code, with corrected errors in it and simplified is:
It gives:
Main changes in code:
join
parameter inbase
style.join
parameter is not desired, are set on the end of "main" nodes and use macroreset join
defined in the preamble of MWE\tikzstyle{ ...}
(now are recommended\tikzset{...}
with styles written as option oftikzpicture