发布比较
在 TikZ 2.10 版本中你可以写:
\coordinate [label={[red] center:$P$}] (x) at (0,0);
但在最新版本(版本 3.0.0)中,除非您在和之间unknown function 'center'
不留任何空格,否则您将收到错误( ) :[options]
<angle>
\coordinate [label={[red]center:$P$}] (x) at (0,0);
相反,如果是<angle>
数字,你仍然可以像以前一样写:
\coordinate [label={[red] 30:$P$}] (x) at (0,0);
问题
这是一个错误还是期望的行为?
平均能量损失
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
%\coordinate [label={[red] center:$P$}] (a) at (0,0); % this doesn't work
\coordinate [label={[red]center:$P$}] (b) at (1,0);
\coordinate [label={[red] 30:$P$}] (c) at (2,0);
\end{tikzpicture}
\end{document}
答案1
令人惊讶的是,找到问题比使用要容易得多\ignorespaces
,感谢聊天中的 David Carlisle,他意识到了我的愚蠢错误,\zap@space
应该加以利用。如果你还没有,这里有更多乐趣我是一名货物崇拜程序员……
无论如何,错误的原因在于代码看起来好像还没有完成。由于没有执行空格吞噬,因此当您在center
它前面发送空格时,它会与定义为的宏进行比较
\def\tikz@on@text{center}
因此,当您将\ifx
它们合并时,它们不匹配,TikZ 认为您发送了一个角度或锚点。剩下的您知道了。作为一个工作示例,我尝试吞噬初始空间进行测试,David Carlisle 修复了我的吞噬机制。宏打开是最初位于tikz.code.tex
文件第 701 行的更改部分。
\documentclass[]{article}
\usepackage{tikz}
\makeatletter
\tikzset{tikz@label@post/.code={% The code has 2 args here WHY? Line 701
\edef\tikz@label@angle{\expandafter\expandafter\expandafter%
\zap@space%
\expandafter\tikz@label@angle\space \@empty}%
\csname tikz@label@angle@is@\tikz@label@angle\endcsname%
\ifx\tikz@label@angle\tikz@on@text%
\def\tikz@node@at{\pgfpointanchor{\tikzlastnode}{center}}%
\def\tikz@anchor{center}%
\else%
\iftikz@absolute%
\pgftransformreset%
\pgf@process{%
\pgfpointshapeborder{\tikzlastnode}%
{\pgfpointadd{\pgfpointanchor{\tikzlastnode}{center}}{\pgfpointpolar{\tikz@label@angle}{1pt}}}}%
\edef\tikz@node@at{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
\tikz@compute@direction{\tikz@label@angle}%
\tikz@addtransform{\pgftransformshift{\pgfpointpolar{\tikz@label@angle}{#1}}}%
\else%
\pgf@process{\pgfpointanchor{\tikzlastnode}{\tikz@label@angle}}%
\edef\tikz@node@at{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
\pgf@xb=\pgf@x%
\pgf@yb=\pgf@y%
\pgf@process{\pgfpointanchor{\tikzlastnode}{center}}%
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\tikz@label@simplefalse%
\iftikz@fullytransformed%
\tikz@label@simpletrue%
\else
\ifdim\pgf@xc=\pgf@xb\relax%
\ifdim\pgf@yc=\pgf@yb\relax%
\tikz@label@simpletrue%
\fi%
\fi%
\fi%
\iftikz@label@simple%
\tikz@compute@direction{\tikz@label@angle}%
\tikz@addtransform{\pgftransformshift{\pgfpointpolar{\tikz@label@angle}{#1}}}%
\else%
\pgf@process{\pgfpointnormalised{%
\pgfpointdiff{\pgfpointtransformed{\pgfqpoint{\pgf@xc}{\pgf@yc}}}{\pgfpointtransformed{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}}%
\edef\pgf@marshal{%
\noexpand\tikz@addtransform{\noexpand\pgftransformshift{\noexpand\pgfpointscale{#1}{
\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}}}%
\pgf@marshal%
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\pgf@x=\pgf@yc%
\pgf@y=-\pgf@xc%
\tikz@auto@anchor%
\fi%
\fi%
\fi}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\coordinate [label={[red] center:$P$}] (a) at (0,0); % this works
\coordinate [label={[red]center:$P$}] (b) at (1,0);
\coordinate [label={[red] 30:$P$}] (c) at (2,0);
\end{tikzpicture}
\end{document}