13

I am working on this example: Simple flow chart

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]
 \begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block] (init) {initialize model};
    \node [cloud, left of=init] (expert) {expert};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {identify candidate models};
    \node [block, below of=identify] (evaluate) {evaluate candidate models};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {is best candidate better?};
    \node [block, below of=decide, node distance=3cm] (stop) {stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(stop);
    \path [line,dashed] (expert) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}
\end{document}

I would like to remove the "update model" node and to connect directly the decision node node and the "identify..." one with an horizontal-vertical-horizontal line. I naively tried to use

 \path [line] (decide) -|- node [near start] {yes} (identify)

but it doesn't work.

Is there any simple way to do this?

hardhu
  • 303

1 Answers1

12

The syntax -|- is not defined by default, so if you want to use it you need to load Qrrbrbirlbel's paths.ortho library.

Another possibility would be to use the |- (or -|) syntax. It represents the intersection point between a vertical and a horizontal line. You can find more information at Flowchart - draw line from node to edge. or How to draw a return arrow from node-3 to node-1.

Using it, it is easy to draw a connection between (decide) and (identify):

    \path [line] (decide) --(decide-|expert) |- (identify);

(decide)--(decide-|expert) draws a line between decide.center to the intersection point defined by a horizontal line across decide.center and a vertical line across expert.center. This line uses decide.center as origin, but it will start to be drawn at decide border.

(decide-|expert) |- (identify) will draw a vertical line with origin at (decide-|expert) which will stop at identify.center y coordinate. From there a horizonta line will be drawn to the (identify) border.

\documentclass[tikz]{standalone}
\usepackage[latin1]{inputenc}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\begin{document}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]
 \begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block] (init) {initialize model};
    \node [cloud, left of=init] (expert) {expert};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {identify candidate models};
    \node [block, below of=identify] (evaluate) {evaluate candidate models};
%    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {is best candidate better?};
    \node [block, below of=decide, node distance=3cm] (stop) {stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) --(decide-|expert) |- (identify);
%    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(stop);
    \path [line,dashed] (expert) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588