How to link different trees with TikZ
No idea what is broken, but is this workaround OK?
Essentially, use one forest
for both trees, with the root as a phantom
node. The s sep
determines the distance between the two trees.
I don't know if/how nodes are named in forest
, so I gave the e
and h
nodes an alias
that I used in the \draw
at the end.
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{forest}
\begin{document}
\begin{forest}
[,phantom,s sep=3cm
[a
[b
[c]
[d]
]
[e,draw,dashed,alias=e]
]
[f
[g]
[,phantom]
[h,alias=h,tikz={\node [draw,dashed,fit=() (!1) (!l)] {};}
[i]
[j]
]
]
]
\draw [-stealth](e) to[bend right] (h.west);
\end{forest}
\end{document}
You can use \subnode:
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{forest}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{minipage}{0.3\textwidth}
\begin{forest}
[a
[b
[c,name=c]
[d,name=d]
]
[\subnode{marke}{e},draw,dashed]
]
\end{forest}
\end{minipage}%
\begin{minipage}{0.3\textwidth}
\begin{forest}
[f
[g]
[,phantom]
[\subnode{markh}{h},name=h,tikz={\node [draw,dashed,fit=() (!1) (!l)] {};}
[i]
[j]
]
]
\end{forest}
\end{minipage}
\begin{tikzpicture}[overlay,remember picture]
\draw[green](marke.east)--(markh.west);
\end{tikzpicture}
\end{document}