4

I created code (below) that creates following figure of consecutive processes. I tried my best to write clean and structured code for a good reproduction:

Screenshot Code

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.multipart, arrows, shadows}

\tikzset{
  bluebox/.style={
  draw,
  rectangle,
  minimum height=4cm,
  fill=blue!25!white,
  align=center,
  inner sep=2ex
  },
  whitebox/.style={
  draw,
  rectangle,
  minimum height=4cm,
  fill=white,
  align=center,
  inner sep=2ex
  },
  item/.style={
  draw,
  inner sep=1ex,
  fill=white 
  },
  matrix/.style={
  draw,
  fill=white,
  text centered,
  minimum height=1em,
  drop shadow
  }
}

\begin{document}

% Stage 1    

\begin{tikzpicture}[font=\sffamily]
\node[bluebox, label={Header 1}] (Stage1) {
  \begin{tikzpicture}
    \node[draw, shape=rectangle split, rectangle split parts=3,
      inner sep=1ex,fill=white] (Inner) {
      \nodepart{one} A
      \nodepart{two} B
      \nodepart{three} C};
\end{tikzpicture}};

% Stage 2    
\node[bluebox, fill=white, right=of Stage1, label={}] (Stage2) {\rotatebox{90}{Stage 2}};

% Stage 3        
\node[bluebox, right=of Stage2, label={Header 3}] (Stage3) {

\begin{tikzpicture}

\tikzstyle{box}=[matrix, scale=0.75]

    \node[] (row1) {%
        \begin{tikzpicture}
            \node (T1) [box] {$T_w$};
            \node (S1) [box,anchor=north] at (T1.south) {$S_1$};
            \node (S2) [box,anchor=north] at (S1.south) {$S_2$};
            \node (SX) [box,anchor=north] at (S2.south) {$S_m$};
        \end{tikzpicture}};

    \node[right=0pt of row1] (row2) {%
        \begin{tikzpicture}
            \node (T1) [box] {$T_w$};
            \node (S1) [box,anchor=north] at (T1.south) {$S_1$};
            \node (S2) [box,anchor=north] at (S1.south) {$S_2$};
            \node (SX) [box,anchor=north] at (S2.south) {$S_m$};
        \end{tikzpicture}};

    \node[right=0pt of row2] (row3) {%
        \begin{tikzpicture}
            \node (T1) [box] {$T_w$};
            \node (S1) [box,anchor=north] at (T1.south) {$S_1$};
            \node (S2) [box,anchor=north] at (S1.south) {$S_2$};
            \node (SX) [box,anchor=north] at (S2.south) {$S_m$};
        \end{tikzpicture}};

\end{tikzpicture}

\begin{tikzpicture}
    \node[item, shape=rectangle split, rectangle split parts=2] (Options) {
        \nodepart{one} Option 1
        \nodepart{two} Option 2};
\end{tikzpicture}};

% Stage 4
\node[whitebox, right=of Stage3, label={}] (Stage4) {\rotatebox{90}{Stage 4}};

% Stage 5
\node[bluebox, right=of Stage4, label={Header 5}] (Stage5) {
\begin{tikzpicture}
        \node[item,shape=rectangle split, rectangle split parts=2, label={Labels}] (Labels) {
          \nodepart{one} "Yes"
          \nodepart{two} "No"};
\end{tikzpicture}};

    \draw[dashed] (Inner.one east) -- (Stage2);
    \draw[dashed] (Inner.two east) -- (Stage2);
    \draw[dashed] (Inner.three east) -- (Stage2);
    \draw[dashed] (Stage2) -- (Stage3);
    \draw[dashed] (Options.one) -- (Stage4);
    \draw[dashed] (Options.two) -- (Stage4);
    \draw[dashed] (Stage4) -- (Stage5);
  \end{tikzpicture}

\end{document}

Here is an outline of the issues with the figure, though I tried my best to write clean code:

  • The matrix in Stage 3 should be smaller and have less horizontal spacing. Also, all boxes should have the same width
  • Option 1 and Option 2 should be positioned central and right of the matrix.
  • Likewise for A, B, C, two dashed lines from Option 1 and Option 2 should connect to Stage 4. However, they originate at nodeparts A and C in Stage 1.
  • In Stage 5, the distance between the item and Labels is too big. I only want to have a small skip
  • Last but not least, all Stage boxes should have the same height, so that the headers align well.

I hope that you can help to resolve some of the problems? Thank you!

4

Like this?

enter image description here

It's not convenient to use nested tikzpictures, therefore, they have been replaced by fit nodes on background layer.

Matrices in stage 3 have been replaced by multipart nodes.

As all inner boxes are vertically aligned and it's height is less than 4cm, all blueboxes in background (and labels above them) are also aligned.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.multipart, arrows, shadows, backgrounds, fit}

\tikzset{
  bluebox/.style={
    draw,
    rectangle,
    minimum height=4cm,
    fill=blue!25!white,
    align=center,
    inner sep=2ex
  },
  whitebox/.style={
    draw,
    rectangle,
    minimum height=4cm,
    fill=white,
    align=center,
    inner sep=2ex
  },
  item/.style={
    draw,
    inner sep=1ex,
    fill=white 
  },
  matrix/.style={
    draw,
    fill=white,
    text centered,
    minimum height=1em,
    drop shadow
  }
}

\begin{document}



\begin{tikzpicture}[font=\sffamily]

% Stage 1     

    \node[draw, shape=rectangle split, 
        rectangle split parts=3,
      inner sep=1ex, fill=white] (Inner) {
      \nodepart{one} A
      \nodepart{two} B
      \nodepart{three} C};

    \begin{scope}[on background layer]
      \node[bluebox, fit=(Inner), label=Stage 1] {};
    \end{scope}

% Stage 2    
\node[bluebox, fill=white, right=of Inner, label={}] (Stage2) {\rotatebox{90}{Stage 2}};

% Stage 3        
    \node[draw, shape=rectangle split, rectangle split parts=4,
      inner sep=1ex, fill=white, right=of Stage2] (Inner1) {
      \nodepart{one} $T_w$
      \nodepart{two} $S_1$
      \nodepart{three} $S_2$
      \nodepart{four} $S_m$};

    \node[draw, shape=rectangle split, rectangle split parts=4,
      inner sep=1ex, fill=white, right=2mm of Inner1] (Inner2) {
      \nodepart{one} $T_w$
      \nodepart{two} $S_1$
      \nodepart{three} $S_2$
      \nodepart{four} $S_m$};

    \node[draw, shape=rectangle split, rectangle split parts=4,
      inner sep=1ex, fill=white, right=2mm of Inner2] (Inner3) {
      \nodepart{one} $T_w$
      \nodepart{two} $S_1$
      \nodepart{three} $S_2$
      \nodepart{four} $S_m$};

    \node[draw, shape=rectangle split, rectangle split parts=2,
      inner sep=1ex, fill=white, right=5mm of Inner3] (option) {
      \nodepart{one} Option 1
      \nodepart{two} Option 2};

    \begin{scope}[on background layer]
      \node[bluebox, fit=(Inner1) (option), label=Stage 3] (Stage3) {};
    \end{scope}

% Stage 4
\node[whitebox, right=of option, label={}] (Stage4) {\rotatebox{90}{Stage 4}};

% Stage 5
        \node[draw, shape=rectangle split, rectangle split parts=2, fill=white, right=of Stage4, label=Labels] (Labels) {
          \nodepart{one} "Yes"
          \nodepart{two} "No"};

    \begin{scope}[on background layer]
      \node[bluebox, fit=(Labels), label=Stage 5] (Stage5) {};
    \end{scope}

    \draw[dashed] (Inner.one east) -- (Stage2);
    \draw[dashed] (Inner.two east) -- (Stage2);
    \draw[dashed] (Inner.three east) -- (Stage2);
    \draw[dashed] (Stage2) -- (Stage3);
    \draw[dashed] (option.one east) -- (Stage4);
    \draw[dashed] (option.two east) -- (Stage4);
    \draw[dashed] (Stage4) -- (Stage5);
  \end{tikzpicture}

\end{document}
3
  • Only point point: When trying to insert a second % Stage 2 (no matter if bluebox or whitebox), the label does not align with the others :/
    – Johnny Joe
    Jan 10 '18 at 12:14
  • I found: The alignment above the boxes depends upon having for instance a "p" or a "g" in the Label. Any idea?
    – Johnny Joe
    Jan 10 '18 at 12:22
  • @JohnnyJoe insert \strut or \vphantom{g} inside every label without descendant strokes (I don't know if its the correct term).
    – Ignasi
    Jan 10 '18 at 15:35

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.