居中旋转的 tikz 标签

居中旋转的 tikz 标签

我有一系列由代码生成的五幅图像,我希望将它们一个接一个地放在一个图中。我想在每个图像的左侧、右侧和底部添加标签(左侧和底部与每个图像相同)。

但是我希望侧面标签旋转 90°,但默认情况下,左侧标签的旋转点在右下角,右侧标签的旋转点在左下角。我不知道如何从中心旋转标签。

\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}

在此处输入图片描述

答案1

PGF 2.10手册第 195 页,关于节点的放置labels,可以阅读:

所选的锚点取决于所选边界点的位置及其相对于主节点中心的位置,以及是否设置了变换形状选项。一般来说,选择应该是您所期望的,但在困难情况下,您可能必须自己设置锚点。

但是没有提供有关如何做到这一点的示例,以及显而易见的选择:

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

不产生任何效果。

因此我将使用额外的节点来标记主要节点:

\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}

结果

相关内容