4

I want to create a flow chart with tikz that looks like this:

-------------------------------
|  wide node                  |
-------------------------------
            |
-------------------------------
|  wide node                  |
-------------------------------
            |
 -------------------------
 |         |              |
------   ------       ------
|sub1|   |sub2|       |sub3|
------   ------       ------
  |        |            |
  -----------------------
           |
-------------------------------
|  wide node                  |
-------------------------------

Looks like a pretty basic flow chart. I tried a lot of stuff to join the arrows and get the sub nodes as wide as the other nodes, but I could not get it to work, my current code looks like this:

\documentclass{minimal}
\usepackage{tikz}

\usetikzlibrary{shapes,arrows,arrows,decorations.pathmorphing,backgrounds,fit,positioning,
shapes.symbols,chains}

\begin{document}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
 text centered, minimum height=4em]
\tikzstyle{dummyblock} = [rectangle]
\tikzstyle{line} = [draw, -latex']
\begin{center}
\begin{tikzpicture}[node distance=3.5cm]
\node [block] (A) {A};
\node [block,below of= A] (B) {B};
\node [dummyblock,below of=B] (BB) {};
\node [block, below of = BB] (D) {D};
\node [block, left of=D] (C) {C};
\node [block, right of=D] (E) {E};
\node [block, below of=D] (F) {F};
\path [line] (A.south) -| (B.north);
\path [line] (B.south) -| (BB.north);
\path [line] (BB.south) -| (C);
\path [line] (BB.south) -| (D);
\path [line] (BB.south) -| (E);
\path [line] (C.south) -| (F.north);
\path [line] (D.south) -| (F.north);
\path [line] (E.south) -| (F.north);
\end{tikzpicture}\end{center}
\end{document}

Does someone have any clue on how to fix this... any help would be much appreciated!

  • Put a dummy coordinate \coordinate (fn) at [yshift=5mm]F.north); and connect C,D,E to it with |- not with -|. – percusse Aug 23 '12 at 13:54
  • Thnx for the reply, how can I connect the lines to the coordinate? I tried the following code: \coordinate (fn at [yshift=5mm]F.north); after \node [block, below of=D] (F) {F}; However now \path [line] (C.south) |- (fn); generates and error... – dikdirk Aug 23 '12 at 14:17
  • Let me write up a proper answer. – percusse Aug 23 '12 at 14:23
3
\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{shapes,arrows,arrows,decorations.pathmorphing,backgrounds,
 fit,positioning,shapes.symbols,chains}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
 text centered, minimum height=4em]
\tikzstyle{dummyblock} = [rectangle]
\tikzstyle{line} = [draw, -latex']


\begin{document}
\begin{tikzpicture}[node distance=3.5cm]
\node [block] (A) {A};
\node [block,below =of A] (B) {B};
\coordinate [below = of B] (BB) {};
\node [block, below = of BB] (D) {D};
\node [block, left  = of D] (C) {C};
\node [block, right = of D] (E) {E};
\coordinate[below = of D] (fn);
\node [block, below = of fn] (F) {F};
\path [line] (A) -- (B);
\draw (B) -- (BB);
\path [line] (BB) -| (C);
\path [line] (BB) -- (D);
\path [line] (BB) -| (E);
\draw (C) |- (fn);
\draw (D) |- (fn);
\draw (E) |- (fn);
\path[line] (fn) -- (F);
\end{tikzpicture}
\end{document}

enter image description here

  • Thnx! Ideally I would like to make the A,B and F blocks wider, i.e. as wide as CDE together. I'll try to combine this with other stuff on this forum, maybe I can get it to work.. – dikdirk Aug 23 '12 at 15:13
  • @dikdirk There you go : tex.stackexchange.com/q/23480/3235 – percusse Aug 23 '12 at 15:16
  • It almost works, only the arrows are not draw straigh for some reason... I have put my code below. Do you any suggestions on how to fix this? – dikdirk Aug 24 '12 at 15:12
2

Percusse, thank you very much for all your help! I combined all the above in the final solution:

\documentclass{minimal}
\usepackage{tikz}

\usetikzlibrary{arrows,positioning,fit}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
text centered, minimum height=4em]
\tikzstyle{line} = [draw, -latex']


\begin{document}
\begin{tikzpicture}[node distance=0.5cm]
\node [block] (D) {D};
\node [block, left  = of D] (C) {C};
\node [block, right = of D] (E) {E};
\coordinate[below = of D] (FF);
\node [ block,  fit={(C) (D) (E)},label=center:F, below = of FF] (F) {};
\coordinate [above = of D] (BB) {};
\node [ block,  fit={(C) (D) (E)},label=center:B, above = of BB] (B) {};
\node [ block,  fit={(C) (D) (E)},label=center:A, above = of B] (A) {};
\path [line] (A) -- (B);
\draw (B) -- (BB);
\path [line] (BB) -| (C);
\path [line] (BB) -- (D);
\path [line] (BB) -| (E);
\draw (C) |- (FF);
\draw (D) |- (FF);
\draw (E) |- (FF);
\path[line] (FF) -- (F);
\end{tikzpicture}
\end{document}

By the way for some reason my linux texlive latex distribution gives errors with (my windows miktex distribution does not give an error):

\node [ block,  fit={(C) (D) (E)},label=center:A, above = of B] (A) {};

this can be resolved by replacing this line with

\node [ block,  fit={(C) (D) (E)}, above = of B] (A) {A};
0

It almost works trough combining all above suggestions:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,arrows}
\tikzstyle{line} = [draw, -latex']
\begin{document}
  \begin{tikzpicture}[node distance=0.2cm,mynode/.style={outer sep=0pt, draw}]
    \node[mynode] (foo)                {foo};
    \node[mynode] (bar) [right=of foo] {bar};
    \node[mynode] (bar2) [right=of bar] {bar2};
    \coordinate[below = of bar] (cbar);
    \node [ mynode,
        inner sep=0pt,
        yshift=-1cm,
        fit={(foo) (bar) (bar2)},label=center:foobar
       ] (foobar) {};
  \draw (foo.south) |- (cbar);
  \draw (bar.south) |- (cbar);
  \draw (bar2.south) |- (cbar);
  \path[line] (cbar) -- (foobar.north);
  \end{tikzpicture}
\end{document}

Only for some reason the arrows are not draw straight from the coordinate below three nodes to the wider node... does anyone know how to fix this?

  • Replace the last line with \path[line] (cbar) -- (cbar |- foobar.north); – percusse Aug 24 '12 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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