2

I have this code:

    % Define block styles
      \tikzstyle{C} = [diamond, draw, fill=blue!20, text width=4.5em, text     badly centered, node distance=3cm, inner sep=0pt]
      \tikzstyle{I} = [chamfered rectangle, minimum width=1.5cm, minimum height=1cm, draw,chamfered rectangle corners=north west]
      \tikzstyle{P} = [chamfered rectangle, minimum width=1.5cm, minimum height=1cm, draw,chamfered rectangle corners=south east] 
      \tikzstyle{V} = [rectangle, draw, minimum width=1.5cm, minimum height=1cm]   
      \tikzstyle{S} = [draw, ellipse,fill=red!70, node distance=3cm, minimum height=2em]
      \tikzstyle{line} = [draw, -latex']
      %------------------------------------------------
     \begin{center}
     \begin{tikzpicture}
      %nodes
     \node [S] (S1) {\textbf{START}};
     \node [I, below of=S1,node distance=1.5cm] (I1) {$ x $};
     \node [I, below of=I1,node distance=1.5cm] (I2) {$ n $};
     \node [C, below of=I2,node distance=2.1cm] (C1) {$ n\>0 $};
     \node [V, below of=C1,node distance=2.1cm] (V1) {$ i\leftarrow 1 $};
     \node [C, below of=V1,node distance=2.1cm] (C2) {$ i\<n $};
     \node [S, right of=C2,node distance=2.7cm] (S2) {\textbf{STOP}};
     \node [V, below of=C2,node distance=2.1cm] (V2) {$ y=x+i $};
     \node [P, below of=V2,node distance=1.5cm] (P1) {$ y $};
     \node [V, below of=P1,node distance=1.5cm] (V3) {$ i\leftarrow i+1 $};
     %arrows
     \begin{scope} [every path/.style=line]
     \path  (S1) -- (I1);
     \path  (I1) -- (I2);
     \path  (I2) -- (C1);
     \path  (C1) -- (V1);  
     \path  (V1) -- (C2);
     \path  (C2) -- (V2);  \path  (C2) -- (S2);
     \path  (V2) -- (P1);  
     \path  (P1) -- (V3);   
     \end{scope}
     \end{tikzpicture}
     \end{center}

and I have this output:

enter image description here

How to get instead the output:

enter image description here

In other words, which kind of command I need in order to get the arrows in blue?

Emma
  • 3,453
  • 12
  • 20
Andrea Leo
  • 1,011
  • 2
    please help us to help you! transform your code sniped to complete document starting with \documentclass{...} used libraries and packages, begin{document} your flowchart \end}doument}. – Zarko Oct 16 '16 at 16:52
  • See for example http://tex.stackexchange.com/questions/55068 and http://tex.stackexchange.com/questions/45347 – Torbjørn T. Oct 16 '16 at 16:59

2 Answers2

3

Define four auxiliary nodes:

\node [coordinate, right of=I2, node distance=2cm] (I2r) {};
\node [coordinate, right of=C1, node distance=2cm] (C1r) {};
\node [coordinate, left of=C2, node distance=2cm] (C2l) {};
\node [coordinate, left of=V3, node distance=2cm] (V3l) {};

Then you can draw the missing arrows by adding these path commands to the scope environment:

\path  (C1) -- (C1r) -- (I2r) -- (I2);
\path  (V3) -- (V3l) -- (C2l) -- (C2);

Do the commands \< and \> really work in your context? I have to use \leq and \geq instead.

Here is the complete code and its output.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\tikzset
  {C/.style={diamond, draw, fill=blue!20, text width=4.5em,
             text badly centered, node distance=3cm, inner sep=0pt
            },
   I/.style={chamfered rectangle, minimum width=1.5cm, minimum height=1cm,
             draw,chamfered rectangle corners=north west
            },
   P/.style={chamfered rectangle, minimum width=1.5cm, minimum height=1cm,
             draw,chamfered rectangle corners=south east
            },
   V/.style={rectangle, draw, minimum width=1.5cm, minimum height=1cm},
   S/.style={draw, ellipse,fill=red!70, node distance=3cm, minimum height=2em},
   line/.style={draw, -latex'}
  }
\begin{tikzpicture}
  \node [S] (S1) {\textbf{START}};
  \node [I, below of=S1,node distance=1.5cm] (I1) {$ x $};
  \node [I, below of=I1,node distance=1.5cm] (I2) {$ n $};
  \node [C, below of=I2,node distance=2.1cm] (C1) {$ n\geq 0 $};
  \node [V, below of=C1,node distance=2.1cm] (V1) {$ i\leftarrow 1 $};
  \node [C, below of=V1,node distance=2.1cm] (C2) {$ i\leq n $};
  \node [S, right of=C2,node distance=2.7cm] (S2) {\textbf{STOP}};
  \node [V, below of=C2,node distance=2.1cm] (V2) {$ y=x+i $};
  \node [P, below of=V2,node distance=1.5cm] (P1) {$ y $};
  \node [V, below of=P1,node distance=1.5cm] (V3) {$ i\leftarrow i+1 $};
  \node [coordinate, right of=I2, node distance=2cm] (I2r) {};
  \node [coordinate, right of=C1, node distance=2cm] (C1r) {};
  \node [coordinate, left of=C2, node distance=2cm] (C2l) {};
  \node [coordinate, left of=V3, node distance=2cm] (V3l) {};
  \begin{scope} [every path/.style=line]
    \path  (S1) -- (I1);
    \path  (I1) -- (I2);
    \path  (I2) -- (C1);
    \path  (C1) -- (V1);  
    \path  (V1) -- (C2);
    \path  (C2) -- (V2);
    \path  (C2) -- (S2);
    \path  (V2) -- (P1);  
    \path  (P1) -- (V3);   
    \path  (C1) -- (C1r) -- (I2r) -- (I2);
    \path  (V3) -- (V3l) -- (C2l) -- (C2);
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

gernot
  • 49,614
2

An alternative solution, which exploit chains library features.

Edit: In case, that you like to have some lines determined by join option, the first solution is extended with new join line type and style, which enable its use

enter image description here

\documentclass[tikz,
               border=5mm]{standalone} 
\usetikzlibrary{arrows, chains, positioning, shapes, shapes.misc}

\makeatletter
\tikzset{suppress join/.code={\def\tikz@after@path{}}}
\makeatother

%------------------------------------------------
\begin{document}
     \begin{tikzpicture}[
     node distance=5 mm and 7mm,
     start chain = going below,
base/.style = {draw, minimum width=1.5cm, minimum height=1cm, 
               align=center, on chain, join=by ->},
   C/.style = {base, diamond, fill=blue!20, inner sep=0pt}, 
   I/.style = {base, chamfered rectangle,  
               chamfered rectangle corners=north west},
   P/.style = {base,chamfered rectangle, draw,chamfered rectangle corners=south east},
   V/.style = {base, rectangle},
   S/.style = {base, ellipse, fill=red!70},
line/.style = {-latex'}
  dl/.style = {-latex', dashed},          % <-- added for dashed "join" lines
 jdl/.style = {suppress join, join= by dl}% <-- enable dashed "join" lines
                        ]
      %nodes
\node [S] (S1) {\textbf{START}};
\node [I] (I1) {$ x $};
\node [I] (I2) {$ n $};
\node [C] (C1) {$ n\geq 0 $};
\node [V] (V1) {$ i\leftarrow 1 $};
\node [C] (C2) {$ i\leq n $};
\node [V] (V2) {$ y=x+i $};
\node [P] (P1) {$ y $};
\node [V,jdl]  % <-- this node is connected with previous by dashed arrow
          (V3) {$ i\leftarrow i+1 $};
%
\node [S, suppress join, right=of C2] (S2) {\textbf{STOP}};
     %arrows
\draw[dl]    (V3.west) -- + (-1,0) |- (C2);% <-- solved OP problem
\draw[line]  (C1.east) -- + ( 1,0) |- (I2) % <-- solved OP problem
             (C2) edge (S2);
     \end{tikzpicture}
\end{document}

In MWE is used correct positioning syntax and node styles definitions. Drawing vertical lines are left to join macro.

Zarko
  • 296,517
  • Your graph differs from the OP's one: One of the new arrows is wrong, and >< should be \geq\leq. – gernot Oct 16 '16 at 17:49
  • fixed! actually OP here have errors in code ... – Zarko Oct 16 '16 at 17:56
  • Hard to tell whether it's an error. Maybe there is a package that defines \> and \< in a suitable way; the OP doesn't show the preamble. – gernot Oct 16 '16 at 17:58
  • One arrow is still wrong: It should not emerge at the STOP node but at the first branch. – gernot Oct 16 '16 at 18:02
  • After recent revision of my answer I unified arrows style (your definition I simplify to line/.style = {-latex'} and move to option of tikzpicture). It is used for style of join lines as well as for drawing other lines. – Zarko Oct 16 '16 at 22:00
  • @Zarko Thank you so much! Chains are very nice! – Andrea Leo Oct 17 '16 at 20:20
  • @Zarko there is a way in order to get just one arrow in chain dashed? – Andrea Leo Oct 17 '16 at 20:49
  • which one? if is part of join is not so simple. You need suppress join and write this line separately. If it is one of back loop lines, just add dashed to \draw option, for example \draw[line,dashed] (V3.west) -- + (-1,0) |- (C2); – Zarko Oct 17 '16 at 20:58
  • @Zarko It works. Thank you. There is a way in order to obtain a dashed arrow just putting 'dashed' instead of suppress join? – Andrea Leo Oct 20 '16 at 10:12
  • In edit of my answer. In it I add option how to make some join arrows (lines) dashed. – Zarko Oct 20 '16 at 13:46