2

Background:

I am trying to add a background to my flow chart and group them into two, namely Quantitative Analysis and Theoretical Analysis.

Relevant Research:

I have tried to understand and modify the codes from:

but couldn't get it right.

Working Code:

\documentclass[a4paper, 11pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{pgfgantt}
\usepackage{geometry}

\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}

\begin{document}

\tikzstyle{rect} = [rectangle, rounded corners, minimum width=4.5cm, minimum height=1cm,text centered, draw=black, fill=blue!10, drop shadow]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[node distance=2cm]

\node (intro) [rect] {Introduction};
\node (method) [rect, below right = 0.75cm and -1.1cm  of intro] {Methodology \& Model};
\node (litrev) [rect, below left = 0.75cm and -1.1cm  of intro] {Literature Review};
\node (result) [rect, below right = 2.50cm and -1.1cm  of intro] {Results};
\node (conc) [rect, below= 4.250cm of intro] {Conclusion};

\draw [arrow] (intro) -| (method);
\draw [arrow] (intro) -| (litrev);
\draw [arrow] (method) -- (result);
\draw [arrow] (result) |- (conc);
\draw [arrow] (litrev) -- (method);
\draw [arrow] (litrev) |- (conc);

\end{tikzpicture}
\end{center}
\caption{Flow chart explaining something} \label{fig:flo}
\end{figure}

\end{document}

Current Output:

enter image description here

Ideal Output:

Excuse my bad MS Paint skills, but I want it to look like this:enter image description here

I would like both of the yellow background planes to be symmetrical and identical in terms of dimensions.

1 Answer 1

4

Very easy with the fit and backgrounds libraries. The aux coordinate is introduced to have symmetric backgrounds.

\documentclass[a4paper, 11pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{pgfgantt}
\usepackage{geometry}

\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}
\usetikzlibrary{fit,backgrounds} % <-added
\begin{document}

\tikzset{rect/.style={rectangle, rounded corners, minimum width=4.5cm, minimum
height=1cm,text centered, draw=black, fill=blue!10, drop shadow},
arrow/.style={thick,->,>=stealth}}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[node distance=2cm]

\node (intro) [rect] {Introduction};
\node (method) [rect, below right = 0.75cm and -1.1cm  of intro,
label={[font=\small\sffamily,name=label1]above right:{Quantitative analysis}}] {Methodology \& Model};
\node (litrev) [rect, below left = 0.75cm and -1.1cm  of intro,
label={[font=\small\sffamily,name=label2]above left:{Theoretical analysis}}] {Literature Review};
\node (result) [rect, below right = 2.50cm and -1.1cm  of intro] {Results};
\node (conc) [rect, below= 4.250cm of intro] {Conclusion};

\draw [arrow] (intro) -| (method);
\draw [arrow] (intro) -| (litrev);
\draw [arrow] (method) -- (result);
\draw [arrow] (result) |- (conc);
\draw [arrow] (litrev) -- (method);
\draw [arrow] (litrev) |- (conc);
\coordinate (aux) at (result.south -| litrev);

\begin{scope}[on background layer]
\node[draw,dashed,gray,rounded corners,fill=yellow!50,fit=(method) (result) (label1)]{};
\node[draw,dashed,gray,rounded corners,fill=yellow!50,fit=(litrev) (label2) (aux)]{};
\end{scope}
\end{tikzpicture}
\end{center}
\caption{Flow chart explaining something} \label{fig:flo}
\end{figure}

\end{document}

enter image description here

EDIT: For completeness: I'd use the shadows.blur library, and it is really straightforward to adjust the boundary of the yellow background box with little tricks.

\documentclass[a4paper, 11pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{pgfgantt}
\usepackage{geometry}

\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}
\usetikzlibrary{fit,backgrounds} % <-added
\usetikzlibrary{shadows.blur}
\begin{document}

\tikzset{rect/.style={rectangle, rounded corners, minimum width=4.5cm, minimum
height=1cm,text centered, draw=black, fill=blue!10,blur shadow},
arrow/.style={thick,->,>=stealth}}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[node distance=2cm]

\node (intro) [rect] {Introduction};
\node (method) [rect, below right = 0.75cm and -1.1cm  of intro,
label={[font=\small\sffamily,name=label1,xshift=-3mm]above right:{Quantitative analysis}}] {Methodology \& Model};
\node (litrev) [rect, below left = 0.75cm and -1.1cm  of intro,
label={[font=\small\sffamily,name=label2,xshift=3mm]above left:{Theoretical analysis}}] {Literature Review};
\node (result) [rect, below right = 2.50cm and -1.1cm  of intro] {Results};
\node (conc) [rect, below= 4.250cm of intro] {Conclusion};

\draw [arrow] (intro) -| (method);
\draw [arrow] (intro) -| (litrev);
\draw [arrow] (method) -- (result);
\draw [arrow] (result) |- (conc);
\draw [arrow] (litrev) -- (method);
\draw [arrow] (litrev) |- (conc);
\coordinate (aux) at (result.south -| litrev);

\begin{scope}[on background layer]
\tikzset{myfit/.style={draw,dashed,gray,rounded corners,fill=yellow!50,
inner sep=10pt}}
\node[myfit,fit=(method) (result) (label1.east)]{};
\node[myfit,fit=(litrev) (aux) (label2.west)]{};
\end{scope}
\end{tikzpicture}
\end{center}
\caption{Flow chart explaining something} \label{fig:flo}
\end{figure}
\end{document}

enter image description here

1
  • This is brilliant! Thank you! - One question, how could I make the Q of Quantitative Analysis and the s of the Theoretical Analysis appear closer to the arrow?
    – 3kstc
    May 16, 2018 at 3:26

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.