2

I used TikZ to create some awesome flow charts, but I still have a hard time to understand how to apply a background to my flow charts. In detail, I would like to have a boarder line around some of the nodes and a text attached on bottom or on top according to the figure below. Currently, my flow chart looks like the following example and related MWE:

Current state:

enter image description here

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,matrix,intersections,positioning,chains}

\begin{document}
\begin{tikzpicture}[node distance = 1.5cm]
% Styles
    \tikzstyle{start} = [rectangle, rounded corners, text width=3cm, minimum height=1cm,text centered, draw=black]
    \tikzstyle{process} = [rectangle, text width=3cm, minimum height=1cm, text centered, draw=black]
    \tikzstyle{arrow} = [thick,->,>=latex]
% Nodes
    \node (P1) [process] {Part 1A};
    \node (start) [start,left of=P1,xshift=-2.8cm] {Start};
    \node (P2) [process,below of=P1] {Part 2A};
    \node (P3) [process,below of=P2] {Part 3A};
    \node (P4) [process,below of=P3] {Part 1B};
    \node (P5) [process,below of=P4] {Part 2B};
    \node (P6) [process,below of=P5] {Part 3B};
    \node (stop) [start,right of=P6,xshift=2.8cm] {End};
% Arrows
    \draw [arrow] (start) -- (P1);
    \draw [arrow] (P1) -- (P2);
    \draw [arrow] (P2) -- (P3);
    \draw [arrow] (P3) -- (P4);
    \draw [arrow] (P4) -- (P5);
    \draw [arrow] (P5) -- (P6);
    \draw [arrow] (P6) -- (stop);
\end{tikzpicture}
\end{document}

Desired state: (I created the boarders with paint. If possibile, I would prefer a dashed border line with correct alignment) enter image description here

D5E
  • 540

1 Answers1

3
  • exploiting is tikz library chains and his macro join
  • added is tikz library fit for rectangles (nodes) with labels TEXT PART A and TEXT PART B
  • for positioning of nodes is used syntax provided by library positioning (right=of start instead of wrong right of=start)

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                fit,            % new
                intersections,  % not used
                matrix,         % not used
                positioning,
                shapes          % not needed
                }

\begin{document}
    \begin{tikzpicture}[
    node distance = 6mm and 8mm,
      start chain = going below,
      base/.style = {draw, semithick, text width=3cm, minimum height=1cm, align=center},
       FIT/.style = {draw, inner sep=2.5mm},
   process/.style = {base, on chain, join=by -Stealth},
     start/.style = {base, rounded corners, on chain, join=by -Stealth},
                        ]
% Nodes
    \node (start)   [start]                     {Start};
    \node (P1)      [process,right=of start]    {Part 1A};
    \node (P2)      [process]                   {Part 2A};
    \node (P3)      [process]                   {Part 3A};
    \node (P4)      [process]                   {Part 1B};
    \node (P5)      [process]                   {Part 2B};
    \node (P6)      [process]                   {Part 3B};
    \node (stop)    [start,right=of P6]         {End};
\node [FIT, fit=(start) (P2),
       label={[anchor=south west, font=\bfseries]south west: TEXT PART A}] {};
\node [FIT, fit=(P3) (stop),
       label={[anchor=north east, font=\bfseries]north east: TEXT PART B}] {};
    \end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517