由于某些原因(为了让节点影响 tikzcd 中指向它的箭头的样式),我需要执行一段代码,该代码读取\tikzlastnode
以获取 tikz(cd) 矩阵中当前位置的名称,但这仅在创建节点后定义。不幸的是,append after command
需要一条路径(空路径显然不是有效输入),所以我需要创建一个假的空节点才能执行一条路径,这听起来真的很肮脏,我担心它可能会导致问题(添加空间,干扰下一个路径……)。我们可以在append after command
完全不干扰路径的情况下运行(或等效)吗?
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-cd}
\begin{document}
\makeatletter
\begin{tikzcd}
A \rar[/utils/exec={\message{BBBBB The message above (AAAA) should be equal to \tikzcd@ar@target}}, draw=\myfillcolor] & |[append after command={
%%% Creating an empty node + /utils/exec sounds really dirty:
node[/utils/exec={%
\message{AAAA I need to have access to the name of the current node \tikzlastnode}%
\gdef\myfillcolor{red}
}%
] {}
}
]| B
\end{tikzcd}
\end{document}
编辑
有人提议了\pgfextra ... \endpgfextra
,而且可行!谢谢!
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-cd}
\begin{document}
\makeatletter
\begin{tikzcd}
A \rar[/utils/exec={\message{BBBBB The message above (AAAA) should be equal to \tikzcd@ar@target}}, draw=\myfillcolor] & |[append after command={%
\pgfextra% this syntax with \endpgfextra completely turns off the tikz syntax, that might be safer than \pgfextra{...}.
\message{AAAA I need to have access to the name of the current node \tikzlastnode}%
\gdef\myfillcolor{red}%
\endpgfextra%
}]| B
\end{tikzcd}
\end{document}