# [Tex/LaTex] How to rotate a TikZ label

rotatingtikz-pgf

I need to place information below and to the right of a grid. I was not able to rotate the label text of a node. I ended up using \rotatebox, but is there a pure TikZ solution?

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (1,1) grid (4,4);
\node[label=below:\rotatebox{-90}{a long text}] at (2.5,1) {};
\node[rotate=-90,label=below:rotate] at (1.5,0.5) {A};
\node[label=right:a long text] at (4,3.5) {};
\end{tikzpicture}
\end{document}


It is perfectly possible to use label in this situation. You just need to rearrange a bit the options and to fiddle around with the placement of the label:

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (1,1) grid (4,4);
\node[label={[label distance=0.5cm,text depth=-1ex,rotate=-90]right:a long text}] at (2.5,1) {};
\end{tikzpicture}
\end{document}


As you can see the idea is to introduce the rotate option as an actual option to the label, not the node. Also, note the options right instead of below and label distance, which are necessary because the system will rotate the label relative to the node. Also, at this point the text might appear a bit off center, so a small hack is needed, to modify the vertical (rotated by -90 degrees at the same time!) position of the label text: text depth=-1ex.