[Tex/LaTex] centering rotated tikz labels

positioningtikz-pgf

I have a series of five image generated from a code that I wish to include one under the other in a figure. I would like to include labels on the left, right and bottom of each of them (left and bottom are identical to each of them).

However I would like the side labels to be rotated by 90°, but it seems that by default the point of rotation is the bottom right of the label on the left and bottom left for the one on the right. I cannot figure out how to rotate the label from its centre.

\PassOptionsToPackage{demo}{graphicx}
\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\node[draw,
    label={[rotate=90]west:years $\rightarrow$},
    label={south:some other text},
    label={[rotate=-90,text=gray]east:OtherLabel}]
    {\includegraphics[width=12cm,height=2.4cm]{somefile1}};
\node[draw, yshift=2.5cm,
    label={[rotate=90]west:years $\rightarrow$},
    label={south:some other text},
    label={[rotate=-90,text=gray]east:OtherLabel}]
    {\includegraphics[width=12cm,height=2.4cm]{somefile2}};
\end{tikzpicture}

\end{document}

enter image description here

Best Answer

In PGF 2.10 manual, at page 195, about the placement of labels in nodes, it can be read:

The anchor that is chosen depends on the position of the border point that is chosen and its position relative to the center of the main node and on whether the transform shape option is set. In general, the choice should be what you would expect, but you may have to set the anchor yourself in difficult situations.

However no example is provided about how to do that, and the obvious option:

\node[draw, yshift=2.5cm,
    label={[anchor=south, rotate=90]west:years $\rightarrow$},
    ...

produces no effect.

So I would use instead extra nodes to label the main ones:

\begin{tikzpicture}
\node[draw,     
      label={south:some other text}] 
      (fig) {\includegraphics[width=12cm,height=2.4cm]{star.mps}};
\node[rotate=90, anchor=south] at (fig.west) {years $\rightarrow$};
\node[rotate=-90, anchor=south,text=gray] at (fig.east) {OtherLabel};
\end{tikzpicture}

Result