1

MWE from another question here:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, backgrounds}

\begin{document}

\centering
\begin{tikzpicture}[%
    block/.style={draw, text width=5em, text centered, rounded corners, minimum height=2em},
    entity/.style={draw, text centerd}
]

  \begin{scope}
    \matrix (A) [matrix of nodes, inner sep=1em, row sep= 2em, column sep= 2em, nodes={block}] {
      & A & \\
      B & & C\\
      & D & \\
      E & & \\
    };
  \end{scope}

    \path (A.north) -- coordinate[pos=.25] (aux1) coordinate[pos=.75] (aux2) (A.south);

\begin{scope}[on background layer]
  \draw[fill=green!30] (A.north west) rectangle (aux1-|A.east);
  \draw[fill=red!30] (A.west|-aux1) rectangle (A.east);
  \draw[fill=blue!30] (A.west) rectangle (aux2-|A.east);
  \draw[fill=orange!30] (A.west|-aux2) rectangle (A.south east);
  \end{scope}
\end{tikzpicture}

\end{document}

Is it possible to add nodes that:

  • can span a whole column of the matrix without making their row oversized
  • and also be covered by the colored bands?
amyspark
  • 628
  • Are multirow nodes supported at all? There is no indication of any such thing as far as I can find in the docs. You can have delimiter nodes at the left and right. Is that what you mean? – cfr May 15 '16 at 01:48

1 Answers1

3

One way is to use fit library of tikz. With minimal change to the code provided in question, I have added some dummy text in empty nodes using \phantom and then used fit library.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, backgrounds,fit}

\begin{document}

\centering
\begin{tikzpicture}[%
    block/.style={draw, text width=5em, text centered, rounded corners, minimum height=2em},
    entity/.style={draw, text centerd}
]

  \begin{scope}
    \matrix (A) [matrix of nodes, inner sep=1em, row sep= 2em, column sep= 2em, nodes={block}] {
        & |[draw=none]| \phantom{A} &  \\
      B &                           & C\\
        & |[draw=none]| \phantom{A} &  \\
      E & |[draw=none]| \phantom{A} &  \\
    };
  \end{scope}

    \path (A.north) -- coordinate[pos=.25] (aux1) coordinate[pos=.75] (aux2) (A.south);

\begin{scope}[on background layer]
  \draw[fill=green!30] (A.north west) rectangle (aux1-|A.east);
  \draw[fill=red!30] (A.west|-aux1) rectangle (A.east);
  \draw[fill=blue!30] (A.west) rectangle (aux2-|A.east);
  \draw[fill=orange!30] (A.west|-aux2) rectangle (A.south east);
  \end{scope}
  \node[fit={(A-1-2) (A-4-2)},block] {Here comes the naughty column};  %% fit here
\end{tikzpicture}

\end{document}

enter image description here