TransWikia.com

Drawing a backward arrow in a flow chart using TikZ

TeX - LaTeX Asked by whitepanda on January 17, 2021

I would like to draw the arrow shown below.

enter image description here

documentclass{article}
usepackage{tikz}
usetikzlibrary{arrows.meta,
                positioning,
                shapes}
               
begin{document}
 noindentresizebox{textwidth}{!}{   begin{tikzpicture}[
 node distance = 5mm and 12mm, 
  block/.style = {draw, rounded corners, fill=#1,
                  minimum height=3em, text width=6em, align=center},
block/.default = white,
decision/.style = {diamond, draw, fill=white!20,
    text width=6em, align=center, minimum height=3em},
every edge/.append style = {draw=black!50, thick, -Latex}
                    ]
node [block] (A) {Initial step};
node [block, right =of A] (B) {Second step};
node [block, above right = of B] (C) {Third step};
node [block, below right = of B] (D) {4th step};
node [decision, below right = of C] (E) {Is  condition met?};

node [block,  right = of E] (F) {Take an action};

path   (A) edge (B);
draw[thick,anchor=west]   (B.+5)  edge  (C.west);         
draw[thick,anchor=west]   (B.-5)  edge  (D.west);    
draw[thick]   (C.+5)  edge  (E.-227.5);         
draw[thick]   (D.+5)  edge  (E.227.5);
draw[thick, anchor=south]   (E)  edge node{Yes} (F);

end{tikzpicture}}
end{document}

I am adding the following line, however, it gives me an error.

draw[thick]  (F.north) | -- ++(2,0) | (A.north);

2 Answers

I think what you want is something like

draw[thick, ->]  (F.north) -- ++(0,3) -| (A.north);

enter image description here

Code:

documentclass{article}
usepackage{tikz}
usetikzlibrary{arrows.meta,
                positioning,
                shapes}
               
begin{document}
 noindentresizebox{textwidth}{!}{   begin{tikzpicture}[
 node distance = 5mm and 12mm, 
  block/.style = {draw, rounded corners, fill=#1,
                  minimum height=3em, text width=6em, align=center},
block/.default = white,
decision/.style = {diamond, draw, fill=white!20,
    text width=6em, align=center, minimum height=3em},
every edge/.append style = {draw=black!50, thick, -Latex}
                    ]
node [block] (A) {Initial step};
node [block, right =of A] (B) {Second step};
node [block, above right = of B] (C) {Third step};
node [block, below right = of B] (D) {4th step};
node [decision, below right = of C] (E) {Is  condition met?};

node [block,  right = of E] (F) {Take an action};

path   (A) edge (B);
draw[thick,anchor=west]   (B.+5)  edge  (C.west);         
draw[thick,anchor=west]   (B.-5)  edge  (D.west);    
draw[thick]   (C.+5)  edge  (E.-227.5);         
draw[thick]   (D.+5)  edge  (E.227.5);
draw[thick, anchor=south]   (E)  edge node{Yes} (F);

draw[thick, ->]  (F.north) -- ++(0,3) -| (A.north);
end{tikzpicture}}
end{document}

Correct answer by Peter Grill on January 17, 2021

Based on my answer on your previous question. Feedback arrow is drawn in two parts: from the last node F to aux coordinate placed above node C and from it to the first node A:

draw[arr]  (F) |- (aux) -| (A);

For this is defined new style arr which is used in above command and in every edge style (used for drawing connections between nodes). In the below proposed solution is not used resizebox, rather are reduced node distance and text width of nodes:

documentclass{article}
%---------------- show page layout. don't use in a real document!
usepackage{showframe}
renewcommandShowFrameLinethickness{0.15pt}
renewcommand*ShowFrameColor{color{red}}
%---------------------------------------------------------------%
usepackage{tikz}
usetikzlibrary{arrows.meta,
                positioning,
                shapes}

begin{document}
%centering
    begin{tikzpicture}[
  node distance = 2mm and 8.8mm,
     arr/.style = {draw=black!50, thick, -Latex},
    base/.style = {draw, font=small,
                   minimum height=2em, text width=4em, align=center},
   block/.style = {base, rounded corners, fill=#1},
 block/.default = white,
decision/.style = {diamond, base, inner xsep=-3pt},
decision/.default = white,
every edge/.append style = {arr}
                    ]
node [block] (A) {Initial step};
node [block, right =of A] (B) {The next step};
node [block, above right = of B] (C) {The third step};
node [block, below right = of B] (D) {The fourth step};
node [decision, below right = of C] (E) {Is condition met?};
node [block, right =of E] (F) {The an action};
%
coordinate[above=of C] (aux);
path   (A) edge (B)
        (B.+5) edge (C.west)
        (B.-5) edge (D.west)
        (C.east) edge (E.north west)
        (D.east) edge (E.south west)
        (E)      edge (F);
draw[arr]  
        (F) |- (aux) -| (A);
    end{tikzpicture}
end{document}

enter image description here

Answered by Zarko on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP