# Connecting arbitrary text in forest

I already asked this question with regard to tikz-qtree (Connecting text in a tikz-qtree with other text by arrow), but maybe there is a better way to do this in forest.

I have the following tree:

\documentclass{article}

\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}},
}

\begin{document}
\begin{forest}
sn edges
[V{[\textit{fin,} SUBCAT $<>$]}
[1 NP{[\textit{nom}]}
[er]]
[V{[\textit{fin}, SUBCAT $<1>$]}
[2 NP{[\textit{acc}]}
[das Buch]]
[V{[\textit{fin}, SUBCAT $<1,2>$]}
[3 NP{[\textit{dat}]}
[dem Mann]]
[V{[\textit{fin}, SUBCAT $<1,2,3>$]}
[gibt]]]]]
\end{forest}

\end{document}


I want to connect the instances of finby double arrows. The best way to do this would be to have some \node declaration around the various fins and connect these nodes. But this somehow does not work. Is there a way to do this?

You need to just set the name as they are arealdy nodes:

\documentclass{article}

\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}},
}

\begin{document}
\begin{forest}
sn edges
[V{[\textit{fin,} SUBCAT $<>$]}
[1 NP{[\textit{nom}]}
[er]]
[V{[\textit{fin}, SUBCAT $<1>$]},name=fin1  %new code
[2 NP{[\textit{acc}]}
[das Buch]]
[V{[\textit{fin}, SUBCAT $<1,2>$]},name=fin2 %new code
[3 NP{[\textit{dat}]}
[dem Mann]]
[V{[\textit{fin}, SUBCAT $<1,2,3>$]},name=fin3 %new code
[gibt]]]]]
\draw[<->] ($(fin1.south west)+(1,.1)$) -- ($(fin2.north west)+(.5,-.1)$);
\draw[<->] ($(fin2.south west)+(1,.1)$) -- ($(fin3.north west)+(.5,-.1)$);
\end{forest}
\end{document}


I was not sure what you wanted to connect, you can use standard node anchors to move the arrows around or bend the arrows, etc.

Edit: for more fine grained control over the arrows origin and end it is possible to use tikzmarks:

\documentclass{article}

\usepackage{forest}
\usetikzlibrary{tikzmark}
\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}},
}

\begin{document}
\begin{forest}
sn edges
[V{[\textit{fin,} SUBCAT $<>$]}
[1 NP{[\textit{nom}]}
[er]]
[V{[\textit{fin}, SUBCAT $<1\tikzmark{m1}>$]},name=fin1  %new code
[2 NP{[\textit{acc}]}
[das Buch]]
[V{[\textit{fin}, SUBCAT $<\tikzmark{m2}1,2>$]},name=fin2 %new code
[3 NP{[\textit{dat}]}
[dem Mann]]
[V{[\textit{fin}, SUBCAT $<1,2,3>$]},name=fin3 %new code
[gibt]]]]]
\draw[<->] ($(fin1.south west)+(1,.1)$) -- ($(fin2.north west)+(.5,-.1)$);
\draw[<->] ($(fin2.south west)+(1,.1)$) -- ($(fin3.north west)+(.5,-.1)$);
\end{forest}
\begin{tikzpicture}[overlay,remember picture]
\draw[<->](pic cs:m1)--(pic cs:m2);
\end{tikzpicture}
\end{document}


• Thanks! Your solution handles the whole node as one object. I want to connect arbitrary text within these nodes. For instance connecting the 1. Your solution seems to use absolute shifts and hence seems to be font dependent. I was trying something like \node (fin1) {\textit{fin}} within the tree nodes, but this did not work. – Stefan Müller Oct 6 '14 at 9:16
• @StefanMüller I added another approach that uses tikzmarks for more fine grained position control. Notice that it needs two compilations to set the drawing straight. – Old Nick Oct 6 '14 at 9:37
• Thanks, but this does not take into account the size of the text. It is just one point, right? I could not refer to the top of the lower 1, could I? – Stefan Müller Oct 6 '14 at 10:26
• @Stefan Muller You can shift the reference point using calc, so something like ($(pic cs:mark1)+(0em,1em)$) or whatever. Use ems as unit measure so that the font size is taken into account. The shifting will be very small anyway. – Old Nick Oct 6 '14 at 10:34