# How to generate a flowchart like in the picture?

Hi all mailing listers:

I want to generate a flowchart like in the picture, which is created by Microsoft Visio. I am a newbie in compiling Tex code. I can generate simple flowchart while the attached one is really complex for me. I don't know how to realize the block shape with being filled texts of "Begin", "Framework A", "Framework B" and "End".

Any suggestion will be greatly appreciated.

PS: I need to fill many mathmatical formulas in this flowchart, so I need Tex coded flowchart. Otherwise, I will directly use Visio-generated one, saving a lot of time especially for a beginner.

Thank you!

• For the begin shape you can refer to TikZ picture shapes where a bunch of style for flow charts are defined. – Claudio Fiandrino Jun 10 '13 at 8:20
• Thanks for your reply. Your provided link is really help. By the way, can you help me draw the the shape of "Framework A"? – user22986 Jun 10 '13 at 16:38

Here's one possibility using a chain (requires the chains library) and some styles; the "Begin" shape was produced using a signal shape (with signal to east and west) from the shapes.symbols library; the "Accept" shape is a diamond from the shapes.geometric library:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,fit,positioning,shapes.symbols,shapes.geometric}

\definecolor{myblue}{RGB}{89,142,213}
\definecolor{myred}{RGB}{199,101,93}

\newcounter{myframe}

\tikzset{
common/.style={
text width=4cm,
align=center,
text depth=1.75ex,
text height=3ex,
thick},
mynode/.style={
common,
draw=#1,
on chain,
join},
mytitle/.style={
common,
draw=none,
fill=#1!20},
every join/.style={->},
begin/.style={
common,
signal,
draw=green!65!black,
signal to=east and west},
accept/.style={
common,
shape aspect=2,
diamond,text width=1.5cm},
end/.style={
common,
draw,
rounded corners=12pt,
text width=2cm}
}

\newcommand\TitleBox[5][15pt]{%
\stepcounter{myframe}%
\node[thick,draw=#4,rounded corners=#1,fit=(#2) (#3),inner xsep=40pt,inner ysep=8pt] (f\themyframe) {};
\fill[#4]
([yshift=-#1-5pt]f\themyframe.north west) --
([yshift=-#1]f\themyframe.north west)
([xshift=#1]f\themyframe.north west) --
([xshift=-#1]f\themyframe.north east)
([yshift=-#1]f\themyframe.north east) --
([yshift=-#1-5pt]f\themyframe.north east) -- cycle;
\node at ([yshift=-0.5*#1-0.3ex]f\themyframe.north) {#5};
}

\begin{document}

\begin{tikzpicture}[
start chain=going below,
>=latex,
node distance = 0.7cm,
yscale=0.9,transform shape
]
\node[begin] (begin) {Begin};

\begin{scope}[every join/.append style={myblue}]
\node[mynode=myblue,below=2cm of begin] (a1) {A1};
\coordinate (aux1) at ([yshift=40pt]a1);
\node[mynode=myblue] (a2) {A2};
\node[mynode=myblue] (a3) {A3};
\end{scope}

\begin{scope}[every join/.append style={myred}]
\node[mynode=myred,yshift=-1.2cm] (b1) {B1};
\coordinate (aux2) at ([yshift=40pt]b1);
\node[mynode=myred] (b2) {B2};
\node[mynode=myred] (b3) {B3};
\node[draw=myred,accept,on chain,join] (acc) {Accept?};
\node[below=-10pt of acc,text width=4cm] (aux3) {};
\end{scope}

\node[mynode=black,below=1.1cm of acc] (c1) {C1};
\node[end,on chain,join] (end) {End};

\node[label=above right:Yes] at (c1.north) {};

\TitleBox{aux1}{a3}{myblue}{Framework A}
\TitleBox{aux2}{aux3}{myred}{Framework B}

\draw[->,myblue] (begin) --  (a1.north);
\draw[->,myred] ([yshift=-12pt]aux2) -- (b1.north);
\draw[->,myred] (acc.east) -- node[above,black] {No} +(17pt,0) |- (b1);
\end{tikzpicture}

\end{document}


The frame with a title around some nodes is produced with the command

\TitleBox[<length>]{<coordinate1>}{<coordinate2>}{<color>}{<title>}


that uses the fit library to produce a fitting shape for the coordinates <coordinate1> and <coordinate2> using the color specified by <color> and produces the title given in the fourth argument. The optional argument gives control over the rounded corners value used (default=15pt).

• Thanks Gonzalo Medina. After I posted the question, I also keep trying to make it, but all failed. Thanks very much. I am so surprised by your amaing work! Thanks! Thanks! Thanks! – user22986 Jun 10 '13 at 21:18
• @user22986 You're welcome! I made some improvements to the code in my updated answer. – Gonzalo Medina Jun 11 '13 at 1:33
• @ Gonzalo Medina I confronted with another problem that the multiple-row texts filled the block of flowchart are still two double line space. This is because the whole document are doubleline space-typed, so how can I force content of flowchart follow singleline space. Thanks! – user22986 Jun 11 '13 at 23:53
• @user22986 That should be a follow-up question, since it's not directly related to the issue discussed here. Please, feel free to open a fresh new question with this new requirement and providing all relevant information (for example, hoe are you producing doublespacing in your document?). – Gonzalo Medina Jun 12 '13 at 0:35