3

I am trying to build a block diagram and achieved as below so far.

enter image description here

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}


\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=5cm]


\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}


\begin{document}

\maketitle

\section{Flowchart}

    \begin{figure}[!h]

        \begin{tikzpicture}[%
            every path/.style={thick, shorten >=2pt, shorten <=2pt},
            node distance=2cm
          ]
            \node (pro1) [process] {K};                 
            \node (pro2) [process, below of=pro1, yshift=-0.5cm] {A};
            \node (pro3) [process, right of=pro2, xshift = 2cm, yshift=1.25cm] {B};     
            \node (pro4) [process, below of=pro2, yshift=-0.5cm] {C};
            \node (pro5) [process, below of=pro4, yshift=-0.5cm] {D};
            \node (pro6) [process, right of=pro5, xshift = 2cm] {E};
            \node (pro7) [process, right of=pro6, xshift = 2cm, yshift=2.5cm] {F};
            \node (pro8) [process, right of=pro7, xshift = 2cm] {G};
            \node (clo1)[cloud, cloud puffs=15.7, right of=pro1, minimum width=3cm, draw, fill=green!20, xshift=8.25cm] {H};



            \begin{scope}[on background layer]
                \node (block1) [container1,fit= { (pro1) (pro2) (pro4) (pro5) }, ] (container) {};
                \node (block2) [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (container) {};
                \node (block3) [container1,fit=(pro8), fill=red!10] (container) {};
            \end{scope}


            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -- (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);


            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);

        \end{tikzpicture}   

        \caption{System Overview} \label{fig:sys_ov}

    \end{figure}


\end{document}

Problems:
1. How do I increase space between background containers? I tried moving, but blocks on them do not move with them complicating things.
2. The arrows do not exactly start from node, but there is a small gap between the arrow endpoint(start or end) and the blocks). how to solve that?
3. I am unable to draw arrow between block and container. For eg, I want to connect C to blue container and also pink at right end.
4. Also how do I have all containers of same height? Min height messes up with alignment of them.

Update 1:
As per AndreC's suggestions, pic has been improvised as below. Only two problems. The arrow from C to block 1 should be straight (from where C is, arrow originating from its right, go straight to meet blue container on the right). Also another arrow should emanate from C from its left, go a round about on the bottom to meet pink container, not currently directly as shown below. How do we do these?

enter image description here

Update 2:
One of above problems in update 1 almost fixed as below. However, the arrow from C to blue is still bent, I want it go straight from C on tis right to blue container. What do we do?

enter image description here

Updated MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=9cm]
\tikzstyle{line} = [draw, -latex']
\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}

\begin{document}
\maketitle
\section{Flowchart}

    \begin{figure}[!htp]

        \begin{tikzpicture}[%
            every path/.style={thick,% shorten >=pt, shorten <=2pt
            },
            node distance=2cm,
          ]

            \node [process] (pro1) at (0,0) {K};                 
            \node [process](pro2) [below=1cm of pro1 ] {A};
            \node [process] (pro3) [right=1cm of pro2, yshift=1cm] {B};     
            \node [process] (pro4) [below= 1cm of pro2] {C};
            \node [process](pro5) [below= 1cm of pro4] {D};
            \node [process](pro6) [right =1cm of pro5,yshift=1cm] {E};
            \node [process](pro7) [right of =pro6, yshift=2cm] {F};
            \node [process](pro8) [right =1cm of pro7] {G};
            \node (clo1)[cloud, cloud puffs=15.7, above=4.5cm of pro7,xshift=2.5cm, minimum width=3cm, draw, fill=green!20] {H};


            \begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,out=0,in=180] (pro4)edge(block2);
                \path[line] (pro4) -| ([xshift=-0.5cm,yshift=-1.5cm]pro5.south west) -| (block3);
            \end{scope}

            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -| (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);

            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);
        \end{tikzpicture}   
        \caption{System Overview} \label{fig:sys_ov}

    \end{figure}
\end{document}

1 Answer 1

2

The code you found somewhere on the net contains a lot of syntax errors. I corrected them.

It does not seem to be yours because problem #2 is caused by the shorten operation which is not documented in manual 3.01a. You will find the documentation on this shorten operation in the manual of version 1.18 on page 109 here http://www.bu.edu/math/files/2013/08/tikzpgfmanual.pdf

Just delete it.

\begin{tikzpicture}[%
            every path/.style={thick, %shorten >=2pt, shorten <=2pt
            },node distance=2cm
          ]

To have nodes of the same height, it is enough to modify the style

\tikzstyle{container1} =[draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=5cm]

and replace minimum height=5cm with minimum height=9cm.

Thus is not correct:

\node (pro1)[process] {K};

you must initially give coordinates. Which gives:

\node[process] (pro1) at (0,0) {K};

Then this code loads the positioning library without using its power. I rewrote with the syntax of this library the nodes (pro1) to (clo1).

    \node [process](pro1) at (0,0) {K};                 
    \node [process](pro2) [below=1cm of pro1 ] {A};
    \node [process](pro3) [above right= 0cm and 2cm of pro2] {B};     
    \node [process](pro4) [below= 1cm of pro2] {C};
    \node [process](pro5) [below= 1cm of pro4] {D};
    \node [process](pro6) [above right =0cm and 2cm of pro5] {E};
    \node [process](pro7) [above right= 1cm and 0 cm of pro6] {F};
    \node [process](pro8) [right =2cm of pro7] {G};
    \node (clo1)[cloud, cloud puffs=15.7, above right=4.5cm and 0cm of pro7, minimum width=2.5cm, draw, fill=green!20] {H};

In order to leave room between the blocks, I simply spaced the nodes B and E even further apart.

The syntax of the nodes containing the blocks was also not correct. By writing

 \node (block1)[container1,fit= { (pro1) (pro2) (pro2) (pro4) (pro5) }, ] (container) {};

you name the node (container) and not (block1)

In the following line you name the second block with the same name (container)

\node (block2)[container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (container) {};

just write

\node[container1,fit= { (pro1) (pro2) (pro2) (pro4) (pro5) }] (block1) {};
\node[container1,fit=(pro3) (pro7) (pro7) (pro6), fill=cyan!20] (block2) {};`

so that the blocks are correctly named.

To create an arrow from C to the next block, simply do it in the existing scope view:

\begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,out=0,in=180] (pro4)edge(block2);
            \end{scope}

Update:

To make an arrow that goes around the blocks, I created a point named (inter) at the bottom left. Then I built the arrow.

 \node [left=1cm of pro4,yshift=-4.3cm](inter){};
 \path [arrow,draw,inner sep=0pt,outer sep=0pt] (pro4)-|(inter.center)-|(block3);

To make the arrow straight, I tinkered by moving point C horizontally and by trial and error found the right length.

 \path [arrow,draw] (pro4.east)--([xshift=2.5cm]pro4.east);

I also shifted node H to the right to make it more aesthetic.

Update 2:

In order for the figure to contain in a page of the article class, it is sufficient to reduce the width of the rectangles and text (2cm instead of 3cm).

\tikzstyle{process} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm,  draw=black, fill=orange!30]

flowchart

\documentclass{article}
\usepackage[utf8]{inputenc}
%\usepackage[margin=1cm]{geometry}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}
\tikzstyle{process} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=9cm]
\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}

\begin{document}
\maketitle
\section{Flowchart}

    \begin{figure}[!h]

        \begin{tikzpicture}[%
            every path/.style={thick,% shorten >=pt, shorten <=2pt
            },
          ]
            \node [process](pro1) at (0,0) {K};                 
            \node [process](pro2) [below=1cm of pro1 ] {A};
            \node [process](pro3) [above right= 0cm and 2cm of pro2] {B};     
            \node [process](pro4) [below= 1cm of pro2] {C};
            \node [process](pro5) [below= 1cm of pro4] {D};
            \node [process](pro6) [above right =0cm and 2cm of pro5] {E};
            \node [process](pro7) [above right= 1cm and 0 cm of pro6] {F};
            \node [process](pro8) [right =2cm of pro7] {G};
            \node (clo1)[cloud, cloud puffs=15.7, above right=4.5cm and 0cm of pro7, minimum width=2.5cm, draw, fill=green!20] {H};

            \begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,draw] (pro4.east)--([xshift=2.5cm]pro4.east);
                \node [left=1cm of pro4,yshift=-4.3cm](inter){};
                \path [arrow,draw,inner sep=0pt,outer sep=0pt] (pro4)-|(inter.center)-|(block3);
            \end{scope}

            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -| (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);

            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);
        \end{tikzpicture}   
        \caption{System Overview} \label{fig:sys_ov}
    \end{figure}
\end{document}

Translated with www.DeepL.com/Translator

16
  • thank you Andre. I created it, but of course, it is a combination of bits and pieces from internet. I started with flowcharts tutorial here, and then tried adding containers at the back via here and improvising.. shorten it I added caz I found a way to use path somewhere I guess. I did not understand what you meant by n°2 though. What is that? Nov 2, 2018 at 11:08
  • thank you for explaining in detail along with the mistakes. Nov 2, 2018 at 11:10
  • Just two more problems I perceive. With C at its current position, can we make straight arrow from right of C to blue container? Also another from left of C to pink container, making a roundabout way going through bottom of page, instead of directly from C to pink container. I have updated the image. Can you please help on that? Nov 2, 2018 at 11:22
  • I managed to get it some what with this at least for 2nd part \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);, but figure goes out on the right due to increased size I guess. Is it good method and how to counter that? Nov 2, 2018 at 11:29
  • Just updated question with latest corrections. Just the arrow needs to be straight form C to blue container without moving C. Nov 2, 2018 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .