# Drawing a line betwen two nodes which are in separate images

Is it possible to draw a line between two circles in the below code?

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}

\tikzset{
crcl/.style={draw, thick, shape=circle }
}

\newcommand*{\MyPic}[2]{
\begin{tikzpicture}
\draw #1 rectangle #2;
\node[crcl] at #1 (c) {};
\end{tikzpicture}
}

\begin{tikzpicture}
\node[fill=blue] at (0,0) (a) {\MyPic{(0,0)}{(1,1)}};
\node[fill=green] [xshift=2cm] at (0,0) (b) {\MyPic{(0,0)}{(1,1)}};
\draw[thick] (a) -- (b);
\end{tikzpicture}
\end{document}

-

This works with the remember picture key and distinctive node names.

This needs at least two compilations.

As an extra, I redefined \MyPic in a more TikZ-way:

\MyPic (<p1>) (<p2>) {<name>}


## Code

\documentclass[tikz]{standalone}
\tikzset{
crcl/.style={draw, thick, shape=circle }
}

\newcommand*{\MyPic}[3]{%
\begin{tikzpicture}[remember picture]
\draw #1 rectangle #2;
\node[crcl] at #1 (c#3) {};
\end{tikzpicture}%
}

\def\MyPic(#1)#2(#3)#4{% remove this if new syntax is not wanted
\begin{tikzpicture}[remember picture] %
\draw (#1) rectangle (#3);        %
\node[crcl] at (#1) (c#4) {};     %
\end{tikzpicture}%                    %
}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{tikzpicture}[remember picture]
\node[fill=blue]              at (0,0) (a) {\MyPic (0,0) (1,1) {a}};
\node[fill=green, xshift=2cm] at (0,0) (b) {\MyPic (0,0) (1,1) {b}};
\draw[thick]                           (ca) -- (cb);
\end{tikzpicture}
\end{document}


## Output

-
Any reason not to just use \tikzmark which sort of packages this kind of solution? –  Peter Grill Dec 20 '12 at 19:45
@PeterGrill Now that you say it, I have tried it: The best I got was an overlayed circle (the bounding box (blue/green) didn’t got updated). The \subnode command sounds promising, though the closest I got was \subnode{salt-#3}{\node[crcl] at #1 (c#3) {};} where I had to use again (ca) and (cb). salt-#3 gives only the center (#1). I want the node “marked” not the point. –  Qrrbrbirlbel Dec 20 '12 at 20:06
Now that I look at it more carefully I guess you'd have to do a custom \tikzmark which places the node. –  Peter Grill Dec 20 '12 at 22:08