1

How can an edged be created between two copies of the same graph structure? The following is an example of the desired output (the labels don't need to be rotated with the object).

Desired Output

Specifically I would like to create two meta objects that contain nodes and connections to those nodes (I think this question might address that). Then I would like to be able to manipulate/copy that meta object and connect a node between the two meta objects(this seems similar, but with two distinct pictures). It is not clear if it is possible to make some combination of the two proposed answers or if I need to attempt something separate.

Brett
  • 276
  • You don't need to create two actually separated objects, you can fake it by drawing that rectangle while it's still only one picture. – Alenanno Apr 28 '16 at 18:29
  • The objects are going to be as simple as those shown in the figure. I made something simple for illustrative purposes. Also, I would like to have the ability to change the object and have that propagate through. – Brett Apr 28 '16 at 18:36
  • What do you mean by "change the object"? – Alenanno Apr 28 '16 at 18:37
  • insert more nodes or edges, change node attributes or edge attributes – Brett Apr 28 '16 at 18:51

1 Answers1

1

Something like this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit}

\tikzset{
    object1/.pic={
        \node[circle,draw] (-A) {A};
        \node[circle,draw, right=of -A] (-B) {B};
        \node[circle,draw, above right=5mm and 1cm of -A] (-C) {C};
        \draw[->] (-A)--(-C);
        \draw[->] (-C)--(-B);
        \node[draw, rounded corners, fit=(-A) (-B) (-C), label={[anchor=north west]north west:Object 1}]{};
    }
}
\begin{document}

\begin{tikzpicture}[remember picture]
\path pic (Obj1) {object1};
\end{tikzpicture}
\hspace{2cm}
\begin{tikzpicture}[remember picture]
\path[blue] pic (Obj2) {object1};
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]
\draw[red,->] (Obj1-B)--(Obj2-A);
\end{tikzpicture}
\end{document}

enter image description here

or this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit}

\tikzset{
    pics/object/.style 2 args={
       code={
        \begin{scope}[rotate=#2, transform shape]
        \node[circle,draw] (-A) {A};
        \node[circle,draw, right=of -A] (-B) {B};
        \node[circle,draw, above right=5mm and 1cm of -A] (-C) {C};
        \draw[->] (-A)--(-C);
        \draw[->] (-C)--(-B);
        \end{scope}
        \node[draw, rounded corners, fit=(-A) (-B) (-C), label={[anchor=north west]north west:Object #1}, inner sep=5mm]{};
        }
    }
}
\begin{document}

\begin{tikzpicture}[remember picture]
\path pic (Obj1) {object={1}{0}};
\end{tikzpicture}
\hspace{2cm}
\begin{tikzpicture}[remember picture]
\path[blue] pic (Obj2) {object={2}{30}};
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]
\draw[red,->] (Obj1-B)--(Obj2-A);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588