如果我指定/tikz/rotate=<degree>
节点以外的某个路径,则意味着将坐标系旋转<degree>
。
考虑以下例子:
rotate
节点内的选项似乎意味着围绕其中心旋转节点。但是当我将rotate
选项与放置选项结合使用时,我很困惑,旋转是如何进行的?
\documentclass[tikz, border=1cm]{standalone}
\tikzset{
base/.style={
minimum height=5mm, minimum width=15mm, draw, rotate=#1
},
A/.style={base=#1},
B/.style={below=1cm, base=#1,},
C/.style={right=1cm, base=#1,}
}
\begin{document}
\begin{tikzpicture}
\fill (0, 0) circle (1pt) node [A={0}] {} node [A={90}] {} node[right] {A};
\fill (0, -1) circle (1pt) node [B={0}] {} node [B={90}] {} node[right] {B};
\fill (1, 0) circle (1pt) node [C={0}] {} node [C={90}] {} node[right] {C};
\end{tikzpicture}
\end{document}
答案1
放置选项实际上是在改变锚点(并可能添加移位)。它们可以在 中查找tikz.code.tex
,
\tikzoption{left}[]{\def\tikz@anchor{east}\tikz@possibly@transform{x}{-}{#1}}%
\tikzoption{right}[]{\def\tikz@anchor{west}\tikz@possibly@transform{x}{}{#1}}%
\tikzoption{above}[]{\def\tikz@anchor{south}\tikz@possibly@transform{y}{}{#1}}%
\tikzoption{below}[]{\def\tikz@anchor{north}\tikz@possibly@transform{y}{-}{#1}}%
这仅仅意味着你围绕该锚点进行旋转。我用点标记这些锚点来说明这一点。
\documentclass[tikz, border=1cm]{standalone}
\tikzset{
base/.style={
minimum height=5mm, minimum width=15mm, draw, rotate=#1
},
A/.style={base=#1},
B/.style={below=1cm,label={[circle,fill,inner sep=1pt,anchor=center]north:{}},base=#1,},
C/.style={right=1cm,label={[circle,fill,inner sep=1pt,anchor=center]west:{}}, base=#1,}
}
\begin{document}
\begin{tikzpicture}
\fill (0, 0) circle (1pt) node [A={0},red] {} node [A={90},blue] {} node[right] {A};
\fill (0, -1) circle (1pt) node [B={0},red] {} node [B={90},blue] {} node[right] {B};
\fill (1, 0) circle (1pt) node [C={0},red] {} node [C={90},blue] {} node[right] {C};
\end{tikzpicture}
\end{document}
如您所见,锚点的位置由below=1cm
或指定right=1cm
,然后形状围绕该锚点旋转。