Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to make a very simple flowchart using tikz.

Here is what it looks like now: Flowchart as it currently looks

And here is what I need it to look like: Flowchart as I want it to look

I've found an example of a flowchart online using tikz, and here is my style definition:

\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=black!25, 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]

and here is my flowchart code:

\begin{figure}[!h]
    \centering
    \begin{tikzpicture}[node distance = 2cm, auto]
        \node [block] (st1) {Stage 1};
        \node [block, right of=st1, node distance=3cm] (st2) {Stage 2};
        \node [block, right of=st2, node distance=3cm] (st3) {Stage 3};
        \path [line] (st1) -- (st2);
        \path [line] (st2) -- (st3);
    \end{tikzpicture}
\end{figure}

If I had just built the image using co-ordinate based shapes, it would have been time consuming but simple just to add the lines and text I need. But since I'm adding these nodes and connecting nodes, I don't know how to add a line with 2 bends.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use relative coordinates.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows}
\tikzset{decision/.style = {diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node
                            distance=3cm, inner sep=0pt},
         block/.style    = {rectangle, draw, fill=black!25, text width=5em, text centered, rounded
                            corners, minimum height=4em},
         line/.style     = {draw, -latex'},
         cloud/.style    = {draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em}
}
\begin{document}
    \begin{tikzpicture}[node distance = 2cm, auto]
        \node [block] (st1) {Stage 1};
        \node [block, right of=st1, node distance=3cm] (st2) {Stage 2};
        \node [block, right of=st2, node distance=3cm] (st3) {Stage 3};
        \path [line] (st1) -- (st2);
        \path [line] (st2) -- (st3);
        %% from st1 draw 1 unit down, then 2 units left (put a node), draw vertically up and then right to reach st1.west
        \path[line,dashed] (st1.south) -- ++(0,-1) -- +(-2,0) node[pos=0.5,below]{Blah1} |- (st1.west) ;
        %% draw 1 unit down from st3.south then horizontally left and up to reach st2.south.
        \path[line,dashed] (st3.south) -- +(0,-1) -|  (st2.south) node[pos=0.25,below]{Blah2} ;    \end{tikzpicture}
\end{document}

enter image description here

Change the pos=<dimen> as you wish. I have also used -| to draw the lines which means draw horizontally first and then vertically. Also, use \tikzset instead of \tikzstyle (which is deprecated).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.