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.

Please consider the following TikZ code:

% aligning text in node: node[align=left] only in latest 2010 tikz:
% http://compgroups.net/comp.text.tex/-tikz-option-for-ragged-left-text-in-node
% or use minipage inside node: http://www.texample.net/tikz/examples/boxes-with-text-and-math/
% or also parbox: http://en.wikibooks.org/wiki/LaTeX/Advanced_Topics
%% note: parbox and minipage width 5em - will extend beyond the minimum width=5em!
% or use /tikz/text ragged:
% http://old.nabble.com/Equal-width-nodes-within-%22matrix-of-nodes%22--td15266855.html
\begin{tikzpicture}[font=\tt]
    \matrix (xA) [anchor=west,text ragged]
    {% 
        \node(xA1) [draw,right,minimum width=5em] {horizon1} ;  \\
        \node(xA2) [draw,right] {horiz2} ;  \\
%       \node(xA3) [draw,anchor=west,minimum width=5em] {\begin{minipage}{5em}hor3\end{minipage}} ; \\
        \node(xA3) [draw,anchor=west,minimum width=5em] {\parbox{5em}{hor3}} ;  \\
    };
    \matrix (yA) [below left=of xA]
    {% 
        \node(yA1) [draw,right,rotate=270] {vert1} ;    &
        \node(yA2) [draw,right,rotate=270] {vert2} ;    &
        \node(yA3) [draw,right,rotate=270] {vert3} ;    \\
    };
    \begin{scope}[rotate=270]
    \matrix (zA) [rotate=270,below left=of yA]
    {% 
        \node(zA1) [draw,right] {horvert1} ;    \\
        \node(zA2) [draw,right] {horvert2} ;    \\
        \node(zA3) [draw,right] {horvert3} ;    \\
    };  
    \end{scope}
\end{tikzpicture}

It generates the following image:

tikz matrix hor/vertical

I would like to achieve something like the yA case - except, I'd like the texts to go 'vert1','vert2','vert3' from right to left (opposite of what is shown) - which would correspond to the xA graphic being rotated for 270 degrees.

So that is what I'm trying to do with the zA case - however, as one can see, there is no rotation whatsoever!

Does this mean that a matrix of nodes cannot be rotated in TikZ? If not, how can I rotate such a matrix?

Thanks in advance for any answer,
Cheers!

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Ah well - I guess this is the answer, pg 487 of the pgfmanual.pdf:

Rotations and scaling. The matrix node is never rotated or shifted, because the current coordinate transformation matrix is reset (except for the translational part) at the beginning of \pgfmatrix. This is intentional and will not change in the future. If you need to rotate the matrix, you must install an appropriate canvas transformation yourself.

However, nodes and stuff inside the cell pictures can be rotated and scaled normally.

... Also, from matrix nodes with sloped option? - pgf-users:

It does say in the manual that it isn't possible (in section 16.2 "Matrices are Nodes"), and that the transformation matrix is reset at the beginning of a matrix. The (internal) use of \halign precludes any kind of fancy transformations. It would be pretty hard to do matrices without using \halign.

... HOWEVER ...

... matrix nodes with sloped option? - pgf-users also says:

Indeed.

However, you can do the following: Put the whole node inside a
tikzpicture, which in turn you put in a node that has the sloped
option. Something like

... (A) -- (B) node[midway,sloped] {\tikz \matrix ...;};

which means that the code above can be modified like this:

\begin{tikzpicture}[font=\tt]
    \matrix (xA) [anchor=west,text ragged]
    {% 
        \node(xA1) [draw,right,minimum width=5em] {horizon1} ;  \\
        \node(xA2) [draw,right] {horiz2} ;  \\
%       \node(xA3) [draw,anchor=west,minimum width=5em] {\begin{minipage}{5em}hor3\end{minipage}} ; \\
        \node(xA3) [draw,anchor=west,minimum width=5em] {\parbox{5em}{hor3}} ;  \\
    };
    \matrix (yA) [below left=of xA]
    {% 
        \node(yA1) [draw,right,rotate=270] {vert1} ;    &
        \node(yA2) [draw,right,rotate=270] {vert2} ;    &
        \node(yA3) [draw,right,rotate=270] {vert3} ;    \\
    };
    \node (zzA) [rotate=270,below left=of yA] {
        \tikz \matrix (zA) 
        {% 
            \node(zA1) [draw,right] {horvert1} ;    \\
            \node(zA2) [draw,right] {horvert2} ;    \\
            \node(zA3) [draw,right] {horvert3} ;    \\
        };  
    };
\end{tikzpicture}

... which will finally result with the originally desired image:

tikz hor/vertical matrix rotation OK

Phew! :) Hope this helps,
Cheers!

share|improve this answer
1  
The problem with subpictures is that you can't reference the (zA1), (zA2) and (zA3) nodes from the outside, except if you use remember picture (but then you must check your node names don't conflict with those from other pictures… –  Georges Dupéron Sep 4 '12 at 9:44
add comment

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.