Using the matrix
-library of TikZ I am producing the following image:
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,font=\small,
every node/.style={inner sep=0pt,rectangle, minimum height=2.5em, text centered},
comp/.style={draw,very thick,text width=2.5cm,fill=blue!10},
crit/.style={draw,text width=2cm}]
\matrix [ampersand replacement=\&,column sep=1.5mm, row sep=3mm]
{
\node [comp] {Category\\One}; \&
\node [crit] {Attribute\\One}; \&
\node [crit] {Attribute\\Two}; \&
\\
\node [comp] {Category\\Two}; \&
\node [crit] {Attribute\\Three}; \&
\node [crit] {Attribute\\Four};
\\
\node [comp] {Category\\Three}; \&
\node [crit] {Attribute\\Five}; \&
\node [crit] {Attribute\\Six}; \&
\node [crit] {Attribute\\Seven};
\\
\node [comp] {Category\\Four}; \&
\node [crit] {Attribute\\Eight}; \&
\node [crit] {Attribute\\Nine}; \&
\node [crit] {Attribute\\Ten}; \&
\\
};
\end{tikzpicture}
\end{document}
Now, I'd like to extend this slightly to achieve such a layout (don't mind the different colours):
I just can't figure how to make one cell span several rows.
Is this possible with matrix
?
Best Answer
I did a bit of cheating here, but I couldn't think a better solution.
Update
Ignasi noticed in a comment that the rectangle at the left does not perfectly align with the other cells, and suggests a workaround. Unfortunately, the workaround does not work, because coordinates
aux1
andaux2
are calculated by tikz at the border of the lines of the cells, so taking into account the line width, andfitting
library will use those coordinates as corners of the new node, at the middle of the border line. I.e. we will get the same result than in above code.However, if we specify a negative
inner sep
for thefit
ted node to counteract the line width, we can achieve perfect alignment.In addition, providing a
text width
to the rotated node allows the insertion of "line breaks" (\\
) as requested by the OP.This is the new code:
And the new result: