Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Using the matrix-library of TikZ I am producing the following image: current layout

\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): target layout

I just can't figure how to make one cell span several rows. Is this possible with matrix?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I did a bit of cheating here, but I couldn't think a better solution.

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,calc}

\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}, anchor=east]
\matrix (m) [ampersand replacement=\&,column sep=1.5mm, row sep=3mm]
{
\node (A) [comp] {Category\\One}; \&
\node [crit] {Attribute\\One}; \&
\node [crit] {Attribute\\Two}; \&
\\
\node [comp] {Category\\Two}; \&
\node [crit] {Attribute\\Three}; \&
\node [crit] {Attribute\\Four};
\\
\node (C) [comp] {Category\\Three}; \&
\node [crit] {Attribute\\Five}; \&
\node [crit] {Attribute\\Six}; \&
\node [crit] {Attribute\\Seven};
\\
\node (D) [comp,text width=4cm] {Category\\Four}; \&
\node [crit] {Attribute\\Eight}; \&
\node [crit] {Attribute\\Nine}; \&
\node [crit] {Attribute\\Ten}; \&
\\
};

\draw[comp] (D.west |- A.north) coordinate (aux1) rectangle ($(C.south west) - (3mm,0mm)$) coordinate (aux2) {};
\node[anchor=center, rotate=90] (X) at ($(aux1)!.5!(aux2)$) {Master one};

\end{tikzpicture}

\end{document}

Result

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 and aux2 are calculated by tikz at the border of the lines of the cells, so taking into account the line width, and fitting 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 the fitted 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:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,calc,fit}

\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}, anchor=east]
\matrix (m) [ampersand replacement=\&,column sep=1.5mm, row sep=3mm]
{
\node (A) [comp] {Category\\One}; \&
\node [crit] {Attribute\\One}; \&
\node [crit] {Attribute\\Two}; \&
\\
\node [comp] {Category\\Two}; \&
\node [crit] {Attribute\\Three}; \&
\node [crit] {Attribute\\Four};
\\
\node (C) [comp] {Category\\Three}; \&
\node [crit] {Attribute\\Five}; \&
\node [crit] {Attribute\\Six}; \&
\node [crit] {Attribute\\Seven};
\\
\node (D) [comp,text width=4cm] {Category\\Four}; \&
\node [crit] {Attribute\\Eight}; \&
\node [crit] {Attribute\\Nine}; \&
\node [crit] {Attribute\\Ten}; \&
\\
};

\coordinate (aux1) at (D.west |- A.north);
\coordinate (aux2) at ($(C.south west) - (3mm,0mm)$);
\node[comp, fit=(aux1)(aux2), inner sep=-.6pt] (X) {}; 
\node[text width=3cm, text centered, anchor=center, rotate=90] at (X.center) {Master\\one};

\end{tikzpicture}
\end{document}

And the new result:

New result

share|improve this answer
2  
I'd suggest using a \node fitting aux1 and aux2 instead of drawing a rectangle. Nodes have anchors in their external border, while rectangles in the middle of the line. If you look carefully, your solutions has master one left and top borders not aligned with Category four left and Category one top borders. –  Ignasi Mar 24 at 20:11
    
Thank you for your answer, JLDiaz. However, if you wouldn't mind, I'd like to leave this question open for a while. The alignment of the nodes doesn't look quite "right", as lgnasi already pointed out including an explanation. –  dhst Mar 24 at 20:31
    
Actually, it works perfectly fine and the offset is barely noticable when printed out. Thanks again! –  dhst Mar 24 at 23:29
1  
@dhst I've updated the answer –  JLDiaz Mar 25 at 0:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.