I have two nodes in tikzpicture and in both nodes there is a graph in nested tikzpicture. Now, I would like an arrow to be pointing from one graph to the other - from the center of one graph to the center of the other graph. That's why the graphs are in the nodes - I can connect the two nodes with arrow. Problem is that edge labels in the second graph are not placed exactly over the edges.
Code:
\documentclass[12pt,a4paper]{standalone}
\usepackage[czech]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows,decorations.pathreplacing, snakes}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[circle, minimum size=0pt, inner sep=0pt, outer sep=0pt, fill=white],
\tikzstyle{vertex}=[circle, minimum size=4pt, inner sep=0pt, fill=orange]
\node(graph) at (0,1) {
\begin{tikzpicture}[font=\footnotesize, thick]
\begin{scope}
\node[vertex] (root) at (4, 5) {};
\node[vertex] (o) at (4, 4) {};
\node[vertex] (oc) at (4, 3) {};
\node[vertex] (a) at (5, 4) {};
\foreach \xfrom/\xto/\xlabel in {
root/o/o, o/oc/c,
root/a/a} {
\draw (\xfrom) to node[pos=0.5]{\xlabel} (\xto);
};
\end{scope}
\end{tikzpicture}
};
\node[right = of graph] (graph2) {
\begin{tikzpicture}[font=\footnotesize, thick]
\begin{scope}
\node[vertex] (root) at (4, 5) {};
\node[vertex] (o) at (4, 4) {};
\node[vertex] (oc) at (4, 3) {};
\node[vertex] (a) at (5, 4) {};
\foreach \xfrom/\xto/\xlabel in {
root/o/o, o/oc/c}
{
\draw (\xfrom) to node[pos=0.5]{\xlabel} (\xto);
};
\foreach \xfrom/\xto/\xlabel in {
root/a/a}
{
\draw (\xfrom) to node[midway]{\xlabel} (\xto);
};
\end{scope}
\end{tikzpicture}
};
\begin{scope}[segment amplitude=4]
\draw[snake=triangles] (graph) -- (graph2);
\end{scope}
\end{tikzpicture}
\end{document}
Possible solution is using of pic
, but that's not exactly what I want, because it chooses one exact point in both graphs and connects them and not the graphs themselves (and so the arrow must be redirected every time the graph changes to lead from its center).
Code:
\documentclass[12pt,a4paper]{standalone}
\usepackage[czech]{babel}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows,decorations.pathreplacing, snakes}
\begin{document}
\tikzset{every node/.style={circle, minimum size=0pt, inner sep=0pt, outer sep=0pt, fill=white},
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]{\xlabel} (\xto);
};
\end{scope}
}
}
\begin{tikzpicture}
\pic (graph) at (0,0) {mygraph=Hallo};
\pic (graph2) at (3,0) {mygraph=Hallo};
\path (grapha) -- (graph2o) coordinate[pos=0.2] (start) coordinate[pos=0.8] (end); \draw[snake=triangles,segment amplitude=4] (start) to (end);
\end{tikzpicture}
\end{document}