There is already quite some discussion about pic mysteries in How to give a name to \pic and How to give a name to \pic (part II). Here is one more issue/observation, which may or may not be related. When answering Shifted edge labels in tikzpictures in nodes side by side with arrow between I learned the nice local bounding box trick from Torbjørn T.'s answer. So I tried to combine this with the pic syntax to make the whole picture referable like a node. (Yes, I know about path pictures, but the problem I see when using these for this purpose is that as far as I know I'd know the size of the thingy before I add all the elements.) My attempt of incorporating this into the definition of the pic is:
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\tikzset{vertex/.style={circle, minimum size=4pt, inner sep=0pt, fill=orange}}
\tikzset{mygraph/.pic={\xdef\myname{\pgfkeysvalueof{/tikz/name prefix}}
\typeout{\myname}
\begin{scope}[font=\footnotesize, thick,local bounding box=\myname]
\node[vertex] (root) at (4, 5) {};
\node[vertex] (o) at (4, 4) {};
\node[vertex] (oc) at (4, 3) {};
\node[vertex] (oco) at (4, 2) {};
\node[vertex] (a) at (5, 4) {};
\foreach \xfrom/\xto/\xlabel in {
root/o/o, o/oc/c, oc/oco/o,
root/a/a} {
\draw (\xfrom) to node[pos=0.5,fill=white]{\xlabel} (\xto);
};
\end{scope}
}
}
\begin{tikzpicture}
\pic (graph1) at (0,0) {mygraph};
\pic (graph2) at (3,0) {mygraph};
\draw[-latex] (graph1) to (graph2);
% just for fun
\draw[-latex,shorten >=1mm,shorten <=1mm] (graph1a) to[out=-10,in=160] (graph2root);
\end{tikzpicture}
\end{document}
As you can see, the arrow starts where it ends. On the other hand, I'd naively expect that the output be the same as the one produced by a code where I put the scope outside the pic:
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\tikzset{vertex/.style={circle, minimum size=4pt, inner sep=0pt, fill=orange}}
\tikzset{mygraph/.pic={\begin{scope}[font=\footnotesize, thick]
\node[vertex] (root) at (4, 5) {};
\node[vertex] (o) at (4, 4) {};
\node[vertex] (oc) at (4, 3) {};
\node[vertex] (oco) at (4, 2) {};
\node[vertex] (a) at (5, 4) {};
\foreach \xfrom/\xto/\xlabel in {
root/o/o, o/oc/c, oc/oco/o,
root/a/a} {
\draw (\xfrom) to node[pos=0.5,fill=white]{\xlabel} (\xto);
};
\end{scope}
}
}
\begin{tikzpicture}
\begin{scope}[local bounding box=graph1]
\pic (graph1) at (0,0) {mygraph};
\end{scope}
\begin{scope}[local bounding box=graph2]
\pic (graph2) at (3,0) {mygraph};
\end{scope}
\draw[-latex] (graph1) to (graph2);
% just for fun
\draw[-latex,shorten >=1mm,shorten <=1mm] (graph1a) to[out=-10,in=160] (graph2root);
\end{tikzpicture}
\end{document}
QUESTION(S): Why is that? How can this be fixed?




\draw[red,ultra thick] (graph1.south east) rectangle (graph1.north west); \draw[blue] (graph2.south east) rectangle (graph2.north west);to see that. So it works if you have\begin{scope}[font=\footnotesize, thick,local bounding box=#1]in thepic, and say e.g.mygraph=ato give the local bb the namea, but that is less convenient. Another method is what Mark Wibrow describes in https://tex.stackexchange.com/a/241737/ – Torbjørn T. May 04 '18 at 08:47