我需要能够在创建节点和绘制路径时引用相同的标识符。现在我尝试\tikz@fig@name
在节点创建期间使用,和\tikztostart
(或\tikztoend
)在路径创建期间使用...虽然它适用于 tikz-cd 矩阵,但它在常规节点(\tikz@fig@name
为空)上失败。理想情况下,我希望这个通用标识符适用于 tikz-cd 矩阵、命名节点和非命名节点...但由于我认为当节点没有名称时不可能绘制链接,因此如果它对无命名节点失败就不那么重要了。
目标是解决这个问题:计算节点边界和路径之间的交点(或者,如何概括 pgfpointshapeborder)
平均能量损失(查看日志以查看节点的名称)
\documentclass[]{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc, positioning,intersections}
\begin{document}
\makeatletter
\tikzset{
defaultNodeStyle/.code={
\tikz@fig@mustbenamed %% <- this forces a name, but when the node already has a name, this name will change... (see logs) Not very useful.
\message{The node name is: \tikz@fig@name}
},
mypath/.style={
to path={
\pgfextra{
\message{The starting point name is: \tikztostart}
\message{The ending point name is: \tikztotarget}
}
(\tikztostart) -- (\tikztotarget) \tikztonodes
},
}
}
\makeatother
\begin{tikzcd}
|[defaultNodeStyle]| A \ar[r,mypath] & |[defaultNodeStyle]| B
\end{tikzcd}
\message{========= Tikzpicture myNodeName(2) ========}
\message{Observe that node names does not match starting points:}
\begin{tikzpicture}
\node[defaultNodeStyle] (myNodeName) {Named};
\node[defaultNodeStyle] (myNodeName2) at (1,1) {Named};
\draw (myNodeName) to[mypath] (myNodeName2);
\end{tikzpicture}
\message{========= Tikzpicture no name ========}
\begin{tikzpicture}
\node[defaultNodeStyle] {No name};
\end{tikzpicture}
\end{document}