如何在定义的两个节点之间绘制箭头pic
?例如,如何从左侧的节点 A 到右侧的节点 A 绘制一条边?谢谢。
我的代码:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, calc}
\begin{document}
\tikzset{
arrow/.style={draw, -latex},
mypic/.pic = {
\node[draw] (a) {A};
\node[draw, below of=a] (b) {B};}
}
\begin{tikzpicture}
\pic at (0,0) {mypic};
\pic at (1,1) {mypic};
\draw[arrow] (a.north east)--(a.south west); % unsurprisingly this doesn't work
\end{tikzpicture}
\end{document}
答案1
您覆盖了节点a
。您需要为其赋予唯一的名称,例如。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, calc}
\begin{document}
\tikzset{
arrow/.style={draw, -latex},
mypic/.pic = {
\node[draw] (#1-a) {A};
\node[draw, below of=#1-a] (#1-b) {B};}
}
\begin{tikzpicture}
\path (0,0) pic {mypic=L};
\path (1,1) pic {mypic=R};
\draw[arrow] (L-a.north east)--(R-a.south west);
\end{tikzpicture}
\end{document}
原则上,您也可以使用图片的名称,请参阅 pgf 手册第 263 页上方的示例。然而,在实践中出现困难,所以我决定走上面的路。