2

I'm new to this latex forum and with the help of the online platform tried to create a flowchart for my work. The code is quoted below. It would be a great help if the following codes are rectified to match my needs. Thanks in advance.

the flow chart

  1. I wish to have the flowchart to be at center.
  2. The arrows connecting the text box of 6-8 and 8-9 should not get overlapped.
  3. The arrow connector b/w the text box 16-2 should be visible and also with 'YES' notes.

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}   
% Define block styles
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered,text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1.5cm, minimum height=0.5cm, text centered,text width=1.5cm,draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance=2cm]
\node (start) [startstop] {Start};
\node (pro1) [process, below of=start] {1};
\node (pro2) [process, below of=pro1,yshift=-0.5cm] {2};
\node (pro2a) [process, left of=pro2,xshift=-2.5cm] {3};
\node (pro3) [process, below of=pro2,yshift=-0.5cm] {4};
\node (pro3a) [process, left of=pro3,xshift=-2cm] {5};
\node (pro3b) [process, right of=pro3,xshift=2cm] {6};
\node (pro3c) [process, right of=pro3b,xshift=1.5cm] {7};
\node (pro4) [process, below of=pro3,xshift=2cm] {8};
\node (pro4a) [process, right of=pro4,xshift=2.5cm] {9};
\node (pro5) [process, below of=pro4] {10};
\node (pro6) [process, below of=pro5,yshift=-0.5cm] {11};
\node (pro7) [process, below of=pro4a,yshift=-1.5cm] {12};
\node (pro8) [process, below of=pro6,yshift=-0.5cm] {13};
\node (pro8a) [process, below of=pro7,yshift=-1.5cm] {14};
\node (pro9) [process, below of=pro8a,yshift=-0.5cm] {15};
\node (dec1) [decision, below of=pro9,yshift=-1cm] {16};
\node (stop)[startstop, below of=dec1,yshift=-1cm] {stop};

\draw [arrow] (start) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro1) -|(pro2a);
\draw [arrow] (pro2a) -- (pro2);
\draw [arrow] (pro2) -- (pro3);
\draw [arrow] (pro3a) -- (pro3);
\draw [arrow] (pro3) -- (pro3b);
\draw [arrow] (pro3c) -- (pro3b);
\draw [arrow] (pro3) |- (pro4);
\draw [arrow] (pro3b)|- (pro4);
\draw [arrow] (pro4)-- (pro4a);
\draw [arrow] (pro4)-- (pro5);
\draw [arrow] (pro5)-- (pro6);
\draw [arrow] (pro4a)-- (pro7);
\draw [arrow] (pro6)-- (pro8);
\draw [arrow] (pro8)-- (pro8a);
\draw [arrow] (pro7)-- (pro8a);
\draw [arrow] (pro8a)-- (pro9);
\draw [arrow] (pro9)-- (dec1);
\draw [arrow] (dec1) -- node[anchor=east] {NO}(stop);
\draw [arrow] (dec1) -- +(6,0)|-(pro2);
\end{tikzpicture}
\end{document}

2 Answers2

3

What I did:

  1. I shrank the whole flowchart using some techniques listed here. I assume that the margin is 1in, but you can change the scale number if your margin is different. I also used figure environment, with \centering.
  2. I changed the beginning point and the ending point of the two arrows with the help of calc library.
  3. I did some tricks, you can see it in the commands I used to draw the arrow.

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage[margin=1in]{geometry}
\usetikzlibrary{shapes,arrows,calc}
\begin{document}
\pagestyle{empty}   
% Define block styles
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered,text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1.5cm, minimum height=0.5cm, text centered,text width=1.5cm,draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [thick,->,>=stealth]
\begin{figure}
\centering
\begin{tikzpicture}[node distance=2cm,scale=0.75,transform shape,font=\Large]
\node (start) [startstop] {Start};
\node (pro1) [process, below of=start] {1};
\node (pro2) [process, below of=pro1,yshift=-0.5cm] {2};
\node (pro2a) [process, left of=pro2,xshift=-2.5cm] {3};
\node (pro3) [process, below of=pro2,yshift=-0.5cm] {4};
\node (pro3a) [process, left of=pro3,xshift=-2cm] {5};
\node (pro3b) [process, right of=pro3,xshift=2cm] {6};
\node (pro3c) [process, right of=pro3b,xshift=1.5cm] {7};
\node (pro4) [process, below of=pro3,xshift=2cm] {8};
\node (pro4a) [process, right of=pro4,xshift=2.5cm] {9};
\node (pro5) [process, below of=pro4] {10};
\node (pro6) [process, below of=pro5,yshift=-0.5cm] {11};
\node (pro7) [process, below of=pro4a,yshift=-1.5cm] {12};
\node (pro8) [process, below of=pro6,yshift=-0.5cm] {13};
\node (pro8a) [process, below of=pro7,yshift=-1.5cm] {14};
\node (pro9) [process, below of=pro8a,yshift=-0.5cm] {15};
\node (dec1) [decision, below of=pro9,yshift=-1cm] {16};
\node (stop)[startstop, below of=dec1,yshift=-1cm] {stop};

\draw [arrow] (start) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro1) -|(pro2a);
\draw [arrow] (pro2a) -- (pro2);
\draw [arrow] (pro2) -- (pro3);
\draw [arrow] (pro3a) -- (pro3);
\draw [arrow] (pro3) -- (pro3b);
\draw [arrow] (pro3c) -- (pro3b);
\draw [arrow] (pro3) |- (pro4);
\draw [arrow] (pro3b)|- ($(pro4.east)+(0,.2)$);
\draw [arrow] ($(pro4.east)+(0,-.2)$)-- ($(pro4a.west)+(0,-.2)$);
\draw [arrow] (pro4)-- (pro5);
\draw [arrow] (pro5)-- (pro6);
\draw [arrow] (pro4a)-- (pro7);
\draw [arrow] (pro6)-- (pro8);
\draw [arrow] (pro8)-- (pro8a);
\draw [arrow] (pro7)-- (pro8a);
\draw [arrow] (pro8a)-- (pro9);
\draw [arrow] (pro9)-- (dec1);
\draw [arrow] (dec1) -- node[anchor=east] {NO}(stop);
\draw [thick] (dec1) -- ($(dec1)+(6,0)$) coordinate (x);
\draw [arrow] (x)--(x|-pro2) node[midway,right] {YES}--(pro2);
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\end{document}

enter image description here

(open the image on a new tab to see it more clearly)

However, you should not use \tikzstyle anymore. Therefore, I think your Define block styles part should be changed to

\tikzset{
    startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
    io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
    process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered,text width=3cm, draw=black, fill=orange!30},
    decision/.style={diamond, minimum width=1.5cm, minimum height=0.5cm, text centered,text width=1.5cm,draw=black, fill=green!30},
    arrow/.style={thick,-stealth},
    line/.style={thick,-stealth}
}
  • Joule, Many thanks for your swift response. Apologies for not providing the text earlier. When I provide the text in the flow-chart, the space between the arrows aren't clear. – bobin albert Mar 31 '19 at 15:35
  • @bobinalbert Could you explain more? The arrows aren't what? –  Mar 31 '19 at 15:37
  • since there is an overlap betwen the process box due to text ....the space between the arrows aren't clear ... – bobin albert Mar 31 '19 at 15:41
  • @bobinalbert You have to reposition the boxes, nothing more. And I know you can do that. –  Mar 31 '19 at 15:42
  • I changed the font size to \normalsize and the results were perfect. Again thanks a lot!!! – bobin albert Mar 31 '19 at 16:05
  • @bobinalbert You are welcome. Glad to hear that! –  Mar 31 '19 at 16:07
  • @JouleV See here: https://tex.stackexchange.com/questions/52372/should-tikzset-or-tikzstyle-be-used-to-define-tikz-styles – CarLaTeX Mar 31 '19 at 17:29
  • @CarLaTeX Yes, if I were in the OP's situation, I would use \tikzset. However, I see that changing from \tikzstyle to \tikzset is not really necessary here. –  Apr 01 '19 at 04:38
  • @JouleV No, it's necessary because \tikzstyle is no more maintained and sooner or later it will cause damage. – CarLaTeX Apr 01 '19 at 04:40
  • @CarLaTeX I don't think so. In your linked question, Till Tantau said that \tikzstyle can still work, we only should change to \tikzset, not must. Yes, I agree that using \tikzset is far more superior, but it is IMHO not strictly necessary to change all the code. (I'm sure that the OP has hundreds of \tikzstyle in his real document - how should he do now!) :) –  Apr 01 '19 at 04:45
  • 1
    @JouleV \tikzstyle is deprecated and it's better not to use it in new answers. – CarLaTeX Apr 01 '19 at 04:50
1
  • as starting point is used @JouleV's answer
  • used is recent tikz syntax
  • for positioning of nodes is used tikz library positioning and its syntax (note, instead of ... of = ... is in it used ... = of ....

    using the syntax of the package positioning have advantages that it defines distances between nodes. consequently all local shifting of node positioning become superfluous.

  • removed is scaling
  • font size is changed to normal size (because in solution is not used any scaling)
  • for straight lines is used command edge (instead --)
  • styles of flowchart elements are slightly reorganized and improved and collected in style "FlowChart" and moved in document preamble (you can select some other name for style) where are now available to any other flowchart in document (if exist)
  • considering above changes code for flowchart is shorter in (to my opinion) more clear

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage[margin=1in]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta, calc, positioning, shapes.geometric}
    
    \tikzset{FlowChart/.style={
         base/.style = {draw,
                        minimum width=24mm, minimum height=8mm, inner sep=1mm, % you can increase node shape size
                        text width=\pgfkeysvalueof{/pgf/minimum width} -2*\pgfkeysvalueof{/pgf/inner xsep},
                        align=center},
    startstop/.style = {base, fill=red!30, rounded corners},
           io/.style = {base, fill=blue!30,
                        trapezium, trapezium stretches body,
                        trapezium left angle=70, trapezium right angle=110,
                        },
      process/.style = {base, fill=orange!30},
     decision/.style = {base, diamond,  aspect=1.3, draw, fill=green!30},
        arrow/.style = {thick,-Stealth},
                                }% end of FlowChart style
            }% end of tikzset
    
    \begin{document}
    \pagestyle{empty}
    \begin{figure}
    \centering
        \begin{tikzpicture}[FlowChart,
        node distance = 5mm and 8mm,
           lbl/.style = {font=\footnotesize}
                            ]
    \node (start) [startstop] {Start};
    \node (pro1)  [process, below = of start] {1};
    \node (pro2)  [process, below = of pro1] {2};
    \node (pro2a) [process, left = of pro2] {3};
    \node (pro3)  [process, below = of pro2] {4};
    \node (pro3a) [process, left = of pro3] {5};
    \node (pro3b) [process, right = of pro3] {6};
    \node (pro3c) [process, right = of pro3b] {7};
    \node (pro4)  [process, below = of $(pro3.south)!0.5!(pro3b.south)$] {8};
    \node (pro4a) [process, right = of pro4] {9};
    \node (pro5)  [process, below = of pro4] {10};
    \node (pro6)  [process, below = of pro5] {11};
    \node (pro7)  [process, below = of pro4a] {12};
    \node (pro8)  [process, below = of pro6] {13};
    \node (pro8a) [process, right = of pro8] {14};
    \node (pro9)  [process, below = of pro8a] {15};
    \node (dec1)  [decision, below = of pro9] {16};
    \node (stop)  [startstop, below = of dec1] {stop};
    % connection lines drawnby "edge"
    \draw [arrow]   (start) edge (pro1)
                    (pro1)  edge (pro2)
                    (pro2a) edge (pro2)
                    (pro2)  edge (pro3)
                    (pro3a) edge (pro3)
                    (pro3)  edge (pro3b)
                    (pro3c) edge (pro3b)
                    ($(pro4.east)+(0,-.2)$) edge ($(pro4a.west)+(0,-.2)$)
                    (pro4)  edge (pro5)
                    (pro5)  edge (pro6)
                    (pro4a) edge (pro7)
                    (pro6)  edge (pro8)
                    (pro8)  edge (pro8a)
                    (pro7)  edge (pro8a)
                    (pro8a) edge (pro9)
                    (pro9)  edge (dec1)
                    (dec1) -- node[lbl, left] {NO} (stop);
    % conection linnes with orthogonal paths
    \coordinate[right= of pro3c] (x);
    \draw [arrow] (pro1) -| (pro2a);
    \draw [arrow] (pro3) |- (pro4);
    \draw [arrow] (pro3b)|- ($(pro4.east)+(0,.2)$);
    \draw [arrow] (dec1) -| node[lbl, pos=0.75,right] {YES} (x) |- (pro2);
    \end{tikzpicture}
    \caption{Caption}
    \label{fig:my_label}
    \end{figure}
    \end{document}
    

enter image description here

(red lines indicate text border)

Zarko
  • 296,517