I want to connect two forest trees with an arrow, in a similar way it is discussed here for plain tikz trees. However, it seems to be impossible to add options to the forest environment in a similar fashion. Simply referencing the nodes will only place the arrow to the right of the right tree. (To avoid confusions: I don't speak about the $\Rightarrow_G$
in the first forest environment, but the bended one, that should connect two specific nodes.)
\documentclass{beamer}
\usepackage{tikz}
\newcommand{\false}{\mathbf{f}}
\usetikzlibrary{calc, positioning}
\usetikzlibrary{arrows}
\usepackage{forest}
\setbeamercovered{transparent}
\begin{document}
\begin{frame}{}
% Tree 1
\begin{forest}
[$\sigma$, calign=last
[$a$]
[{\langle \sigma, \{1,2\},\false \rangle}%
, math content, calign=first, baseline, draw=blue, ellipse, name = replaceNode
[$\sigma_*$]
[$a$]
]
]
\node at (current bounding box.east)
[anchor=west]
{$\Rightarrow_G$};
\end{forest}
%
% Tree 2
\begin{forest}
[$\sigma$, calign=last
[$a$]
[$\sigma$, calign=last
[$b$]
[{\langle \sigma, \{1,2\},\false \rangle}%
, math content, calign=first, baseline, name = t1
[$\sigma$, calign=first
[$\sigma_*$]
[$a$]
]
[$b$]
]
]
]
\end{forest}
%
% This arrow should connect two nodes of both trees.
\begin{tikzpicture}
\draw[->, black, dashed, bend angle=45, bend left] (replaceNode) to (t1);
\end{tikzpicture}
\end{frame}
\end{document}
There seems to be the workaround of putting both trees in the same forest environment with a phantom parent node. However, I would appreciate an overlay solution for better modularity of my graphics, especially if more than two trees are involved.
Best Answer
As @cfr suggested in the comment section, this can be done by making use of the
tikzmark
library.You need to add
\usetikzlibrary{tikzmark}
to your preamble. Then, you can put a\subnode
in eachforest
environment and then add atikzpicture
after that with the optionsoverlay
andremember picture
.When you issue the
\draw
command, you can prefix the names of thesubnode
s withpic cs:
, if you want to treat thatsubnode
as a coordinate point (otherwise don't use thepic cs:
prefix). Note that you will also need to compile the document twice.I've also moved the starting point and ending point of the arrow up and over a bit by using the
($()+()$)
syntax for specifying a coordinate position.