现在转换的执行顺序是不是就是,如果转换命令在之后\tikz@addtransform
,则在之后执行,否则就执行?
这个问题源于以下例子:
\documentclass[tikz, border=1cm]{standalone}
\tikzset{
base/.style={
minimum height=5mm, minimum width=15mm, draw, rotate=#1
},
A/.style={base=#1},
B/.style={base=#1, below=1cm},
}
\begin{document}
\begin{tikzpicture}
\node [A=90] (a) at (0, 0) {};
\node [B=90, red] (b) at (a.south) {};
\usetikzlibrary{positioning}
\node [B=90, blue] (b) at (a.south) {};
\end{tikzpicture}
tikz.code.tex
我查阅了和中的代码tikzlibrarypositioning.code.tex
。我发现的区别是移位转换代码:
tikz.code.tex
有一个\tikz@addtransform
之前变换操作
\tikzoption{below}[]{\def\tikz@anchor{north}\tikz@possibly@transform{y}{-}{#1}}%
\def\tikz@possibly@transform#1#2#3{%
\let\tikz@do@auto@anchor=\relax%
\def\tikz@test{#3}%
\ifx\tikz@test\pgfutil@empty%
\else%
\pgfmathsetlength{\pgf@x}{#3}%
\pgf@x=#2\pgf@x\relax%
\edef\tikz@marshal{\noexpand\tikz@addtransform{%
\expandafter\noexpand\csname pgftransform#1shift\endcsname{\the\pgf@x}}}%
\tikz@marshal%
\fi%
}%
虽然在转换之前tikzlibrarypositioning.code.tex
没有\tikz@addtransform
\tikzset{below/.code=\tikz@lib@place@handle@{#1}{north}{0}{-1}{south}{1}}%
\def\tikz@lib@place@handle@#1#2#3#4#5#6{%
\def\tikz@anchor{#2}%
\let\tikz@do@auto@anchor=\relax%
\edef\tikz@temp{#1}%
\def\tikz@lib@place@single@factor{#6}%
\expandafter\tikz@lib@place@handle@@\expandafter{\tikz@temp}{#3}{#4}{#5}%
}%
\def\tikz@lib@place@handle@@#1#2#3#4{%
\pgfutil@in@{of }{#1}%
\ifpgfutil@in@%
\tikz@lib@place@of#1\tikz@stop{#4}%
\else%
\edef\tikz@lib@place@nums{#1}%
\fi%
\ifx\tikz@lib@place@nums\pgfutil@empty%
Ok, nothing to do, we have set the anchor and we are happy...
\else%
\expandafter\tikz@lib@place@parse@nums\expandafter{\tikz@lib@place@nums}%
\pgf@x=#2\pgf@x%
\pgf@y=#3\pgf@y%
\edef\tikz@lib@pos@call{\noexpand\pgftransformshift{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
\fi%
}%
如果真正的原因正如我猜测的那样,为什么positioning
不使用\tikz@addtransform
?
答案1
我认为你说得对。你可以看看\tikz@addtransform
,
\def\tikz@addtransform#1{%
\ifx\tikz@transform\relax
#1%
\else
\expandafter\def\expandafter\tikz@transform\expandafter{\tikz@transform#1}%
\fi
}%
因此它添加了一个稍后执行的转换\tikz@transform
。除了您提到的效果之外,在更新时也可以看到此效果node distance
。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[nodes={circle,draw,inner sep=10pt},node distance=2cm]
\node (A) at (0,2){};
\node[right of=A,blue] (A-1){};
\node[right of=A,node distance=4cm,dashed,red] (A-2){};
\node[node distance=4cm,right of=A,dashed,cyan,inner sep=20pt] (A-3){};
\node (B) at (0,0){};
\node[right=of B,blue] (B-1){};
\node[right=of B,node distance=4cm,dashed,red] (B-2){};
\node[node distance=4cm,right=of B,dashed,cyan,inner sep=20pt] (B-3){};
\end{tikzpicture}
\end{document}
node distance
如您所见,当您使用内置(但已弃用)的相对定位节点方式时,更新之前或之后都无关紧要right
。另一方面,如果您使用positioning
,则需要更新。
\tikz@addtransform
原则上,也可以考虑在positioning
库中使用。但是,这会破坏现有的编码。但是,请参见问题 869它处理的是是否应该做出改变的问题。