# Complex Flowchart with Boxes within a Dotted Box using TikZ

I'm trying to produce the following flowchart with adding multiple dotted backgrounds. I know the basics for creating a simple flowchart using Tikz, however, I'd like to know how I can create a flowchart which is a bit complicated as shown below. I created the figure in MS PowerPoint.

MWE for the simple flow-chart I created:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{shapes.multipart}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[
node distance=2cm
]
\node (pro1) [process, below of=in1,yshift=-0.5cm] {Meshing\\A};
\node (pro0) [process, left of=pro1, xshift=-2.5cm] {Design\\A};
\node (pro2) [process, below of=pro1,yshift=-0.5cm] {solver setup};
\node (pro) [process, right of=pro2, xshift=2.5cm] {A\\+\\B};

\node (dec1) [decision, below of=pro2, yshift=-0.8cm] {i = N?};
\node (dec2) [decision, left of=dec1, xshift=-2.5cm] {Converged?};
\node (pro5) [process, left of=dec2, xshift=-2.5cm] {i = i+1};
\node (pro6) [process, below of=dec1, yshift=-1cm] {Post processing};
\draw [arrow] (pro0) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro) -- (pro2);

\draw [arrow] (pro2) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=south] {No} (dec2);
\draw [arrow] (dec2) -- node[anchor=south] {No} (pro5);
\draw [arrow] (pro5) |- (pro2);
\draw [arrow] (dec1) -- node[anchor=west] {Yes} (pro6);
\draw [arrow] (dec2) |- node[anchor=north] {Yes} (pro6);
\end{tikzpicture}
\end{figure}

\end{document}


This provides a simple output: However, I'm looking for a much complicated output as shown below: • You can take some ideas from this example texample.net/tikz/examples/flowchart Apr 21, 2022 at 13:58
• Your example starts by below of=in1 where no node is named in1. Please edit it to make it compilable. Now for what you're looking for, you should find the fit library useful. Apr 21, 2022 at 17:05
• @AndreyL.: Thanks! Apr 21, 2022 at 21:16
• @SebGlav: I see that now. I forgot to edit that. Apr 21, 2022 at 21:16

Here's something very generic, just to show the use of the fit library in this particular case.

Note that I repaced all your tikzstyle by tikzset, which are the modern way of designing styles in TikZ. \documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, fit}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{shapes.multipart}
\tikzset{
startstop/.style =
{rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
io/.style =
{trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,draw=black, fill=blue!30},
process/.style = {rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30},
decision/.style = {diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
arrow/.style = {thick,->,>=stealth},
myfit/.style={draw,dashed,blue, inner xsep=10pt, inner ysep=15pt, rounded corners=5pt},
mytitle/.style={draw,densely dashed,blue, fill=orange!50, inner sep=5pt, right, xshift=10pt}
}

\begin{document}

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[
node distance=2cm
]
\node (pro1) [process, yshift=-0.5cm] {Meshing\\A};
\node (pro0) [process, left of=pro1, xshift=-2.5cm] {Design\\A};
\node (pro2) [process, below of=pro1,yshift=-0.5cm] {solver setup};
\node (pro) [process, right of=pro2, xshift=2.5cm] {A\\+\\B};

\node (dec1) [decision, below of=pro2, yshift=-0.8cm] {i = N?};
\node (dec2) [decision, left of=dec1, xshift=-2.5cm] {Converged?};
\node (pro5) [process, left of=dec2, xshift=-2.5cm] {i = i+1};
\node (pro6) [process, below of=dec1, yshift=-1cm] {Post processing};
\draw [arrow] (pro0) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro) -- (pro2);

\draw [arrow] (pro2) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=south] {No} (dec2);
\draw [arrow] (dec2) -- node[anchor=south] {No} (pro5);
\draw [arrow] (pro5) |- (pro2);
\draw [arrow] (dec1) -- node[anchor=west] {Yes} (pro6);
\draw [arrow] (dec2) |- node[anchor=north] {Yes} (pro6);

\node[fit=(pro1)(pro0),myfit] (myfit1) {};
\node[mytitle] at (myfit1.north west) {Pre-processing};
\draw[arrow,blue] (myfit1) -| (pro);

\end{tikzpicture}
\end{figure}

\end{document}

• Thanks, @SebGlav. Appreciate it. Apr 21, 2022 at 21:16
• Can I also use \node for drawing multiple nodes inside the dotted box for 'Solver set-up' as shown in my 2nd picture attached in the post? That part was a bit complex for me. Apr 21, 2022 at 21:35
• Every node can be drawn with \node. In this particular case, I recommand to use matrix of nodes. You could ask for this specific part in another question. Apr 22, 2022 at 6:15
• Thanks, @SebGlav! Apr 22, 2022 at 6:27
{"ft_lang_label":"__label__en","ft_lang_prob":0.61351734,"math_prob":0.8913233,"size":2478,"snap":"2023-40-2023-50","text_gpt3_token_len":838,"char_repetition_ratio":0.12853678,"word_repetition_ratio":0.047945205,"special_character_ratio":0.3071025,"punctuation_ratio":0.19956616,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99381775,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-08T08:46:11Z\",\"WARC-Record-ID\":\"<urn:uuid:f4d8393e-e98b-42d3-bc65-375b137b962a>\",\"Content-Length\":\"156158\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8476ad9a-a079-407e-b476-b7a6d23299e7>\",\"WARC-Concurrent-To\":\"<urn:uuid:79eb28ce-29d2-4344-a803-0b06dfae31f1>\",\"WARC-IP-Address\":\"104.18.43.226\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/641500/complex-flowchart-with-boxes-within-a-dotted-box-using-tikz\",\"WARC-Payload-Digest\":\"sha1:LRKEVGRRW7DSQWQZGJTB5WHBLAOJFUPN\",\"WARC-Block-Digest\":\"sha1:P4F2GLETVO3WDCIJU4YRJLARWNFAHMJK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100739.50_warc_CC-MAIN-20231208081124-20231208111124-00450.warc.gz\"}"}