1

How can I draw an arrow between two nodes that are defined in a pic please. For example, how can I draw an edge from node A in the left hand side to the node A in the right hand side? Thank you.

enter image description here

My code:

\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}
3
  • @Schrödinger'scat; no, I'd like to draw an edge between the nodes from the different pics. i.e from A to A, and B to B. Perhaps I should add label parameters to the pics? – user20650 Nov 11 '19 at 16:00
  • 1
    Oh, sorry! OK. I see. Tried to answer this below. – user194703 Nov 11 '19 at 16:04
  • Thanks @Schrödinger'scat – user20650 Nov 11 '19 at 16:06
2

You overwrite the node a. You need to give it unique names, e.g. with.

\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}

enter image description here

In principle you could also use the names of the pics, see the example on top of p. 263 of the pgf manual. However, in practice difficulties arise, so I decided to go the way above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.