![箭头、坐标和标签](https://linux22.com/image/330935/%E7%AE%AD%E5%A4%B4%E3%80%81%E5%9D%90%E6%A0%87%E5%92%8C%E6%A0%87%E7%AD%BE.png)
请考虑下面的 MWE。
\documentclass[border=3mm,
tikz,
preview]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
LM/.style = {
very thin,
{Bar[width=3.4mm]Straight Barb[]}-%
{Straight Barb[]Bar[width=3.4mm]}
},
every pin/.style = {
inner sep=1pt, align=center, text=teal!20!black,
font=\footnotesize\sffamily,
pin edge={{Straight Barb[]}-, solid, black}
},
]
\draw[LM] (0,0) -- node[pin=right:text] {} + (0,0.5);
\draw[LM] (0,1) -- node[coordinate,pin=right:text] {} + (0,0.5);
\draw[LM] (0,2) -- coordinate[pin=right:text] (a) + (0,0.5);
\draw[LM] (0,3) -- node[inner sep=0pt,pin=right:text] {}+ (0,0.5);
\draw[LM] (2,0) -- node[pin=above:text] {} + (0.5,0);
\draw[LM] (3,0) -- node[coordinate,pin=above:text] {} + (0.5,0);
\draw[LM] (4,0) -- coordinate[pin=above:text] (a) + (0.5,0);
\draw[<->] (2,1) -- node[pin=above:text] {} + (0.5,0);
\draw[<->] (3,1) -- node[coordinate,pin=above:text] {} + (0.5,0);
\draw[<->] (4,1) -- coordinate[pin=above:text] (a) + (0.5,0);
\end{tikzpicture}
\end{document}
为什么当节点中存在选项coordinate
或者使用节点与pin
选项协调时箭头会变形?
答案1
让我们修正这个符号。
\draw[<->](A)--node[pin=Dpin]{Conline}(B);
钛钾Z 将会
- 处理该行
(A)--(B)
,并将其推入缓冲区; - 创建节点
Conline
; - 创建节点
Dpin
; - 处理线
(Conline)edge(Dpin)
,立即绘制;(A)--(B)
仍在缓冲区中;
- 向缓冲区中的最后一条子路径添加箭头;
- 如此
(A)<->(B)
画出。
- 如此
在上述场景中,edge
Ti 是单独处理的钾Z 确实将箭头附加到正确的子路径。
如果Conline
恰好是a coordinate
,则Ti钾Z 将会
- 处理该行
(A)--(B)
,并将其推入缓冲区; - 创建坐标
Conline
; - 创建节点
Dpin
; - 处理线
(Conline)edge(Dpin)
,立即绘制;(Conline)
发射一个moveto
令牌;- 现在缓冲区变成了
(A)--(B) (Conline)
;
- 向缓冲区中的最后一个子路径添加箭头;
- 如此
(A)--(B) (Conline)^
画出。
- 如此
这里^
表示 Ti钾Z 尝试将箭头附加到由单个点组成的子路径。每次这样做时,箭头始终指向上方。
为了防止 acoordinate
触发token,你可以对和moveto
的顺序进行 sqap 。也就是说,(Conline)
(Dpin)
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{arrows.meta}
\makeatletter
\long\def\tikz@@parse@pin@nonactive[#1]#2:#3:\pgf@nil{%
\tikzset{%
append after command = {%
\bgroup
[current point is local = true]
\pgfextra{\let\tikz@save@last@node=\tikzlastnode\tikz@node@is@a@labelfalse}%
node [every pin,
tikz@label@angle = #2,
anchor=@auto,
#1,
append after command = {%
(\tikzlastnode) %%%% swap this node
edge [every pin edge,
tikz@pre@pin@edge,
tikz@pin@options]
(\tikz@save@last@node)}, %%%% with this node
tikz@label@post = \tikz@pin@distance,
tikz@pin@post] {#3}
\egroup}}}
\begin{document}
\begin{tikzpicture}[
LM/.style = {
very thin,
{Bar[width=3.4mm]Straight Barb[]}-%
{Straight Barb[]Bar[width=3.4mm]}
},
every pin/.style = {
inner sep=1pt, align=center, text=teal!20!black,
font=\footnotesize\sffamily,
pin edge={{Straight Barb[]}-, solid, black}
},
]
\draw[LM] (0,0) -- node[pin=right:text] {} + (0,0.5);
\draw[LM] (0,1) -- node[coordinate,pin=right:text] {} + (0,0.5);
\draw[LM] (0,2) -- coordinate[pin=right:text] (a) + (0,0.5);
\draw[LM] (0,3) -- node[inner sep=0pt,pin=right:text] {}+ (0,0.5);
\draw[LM] (2,0) -- node[pin=above:text] {} + (0.5,0);
\draw[LM] (3,0) -- node[coordinate,pin=above:text] {} + (0.5,0);
\draw[LM] (4,0) -- coordinate[pin=above:text] (a) + (0.5,0);
\draw[<->] (2,1) -- node[pin=above:text] {} + (0.5,0);
\draw[<->] (3,1) -- node[coordinate,pin=above:text] {} + (0.5,0);
\draw[<->] (4,1) -- coordinate[pin=above:text] (a) + (0.5,0);
\end{tikzpicture}
\end{document}
当然这意味着 nowpin edge={->}
指向Conline
。这肯定不是向后兼容的。但我相信改变 a 的行为coordinate
更加危险。