2

According to the tikzmark documentation, when using \subnode, it should be

possible to use ordinary node syntax (within a tikzpicture) to access this information. Thus after \node {a \subnode{a}{sub} node}; it is possible to use a as a node.

After reading the documentation, using \subnode works as I would expect when drawing trees with tikz-qtree but not when drawing trees with forest.

This code produces the following tree, as desired.

\documentclass[varwidth=\maxdimen, border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=center, anchor=north}}

\begin{document}
\begin{tikzpicture}[remember picture]
\Tree
[.TP
  [.NP \edge[roof]; {someone} ]
  [.T$'$
    [.\node(T){T};  ]
    [.VP
      [.V$'$
        [.V\\\subnode{eat}{eat}\\{\ldots}\\{\ldots} ]
        [.NP \edge[roof]; {the pie} ]
      ]
    ]
  ]
]
\draw[->] (T) to[in=-180, out=-75] (eat);
\end{tikzpicture}

\end{document}

enter image description here

Whereas this code produces the following tree, which is not desired.

\documentclass[varwidth=\maxdimen, border=5pt]{standalone}

\usepackage[linguistics]{forest}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{forest} remember picture
[TP
  [NP
    [someone, roof]
  ]
  [T$'$
    [T, name=T]
    [VP
      [V$'$
        [V\\\subnode{eat}{eat}\\\ldots\\\ldots]
        [NP
          [{the pie}, roof]
        ]
      ]
    ]
  ]
]
\draw[->] (T) to[in=-180, out=-75] (eat);
\end{forest}

\end{document}

enter image description here

It seems that forest isn't picking up the remember picture option, so should I be setting this differently? If so, how?

Adam Liter
  • 12,567

1 Answers1

1

This is always a bit tricky because there are two separate "remembering" mechanisms at work. So you may just use two subsides and connect them in the usual way, i.e. with an overlay,remember picture.

\documentclass[varwidth=\maxdimen, border=5pt]{standalone}

\usepackage[linguistics]{forest}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{forest} 
[TP
  [NP
    [someone, roof]
  ]
  [T$'$
    [\subnode{T}{T}]
    [VP
      [V$'$
        [V\\\subnode{eat}{eat}\\\ldots\\\ldots]
        [NP
          [{the pie}, roof]
        ]
      ]
    ]
  ]
]
\end{forest}
\begin{tikzpicture}[overlay,remember picture]
\draw[->] (T) to[in=-180, out=-75] (eat);
\end{tikzpicture}
\end{document}

enter image description here

Another possibility is to use \subnodes only to measure relative positions. This cancels the offset error. One has to account for the inner sep, though.

\documentclass[varwidth=\maxdimen, border=5pt]{standalone}

\usepackage[linguistics]{forest}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{forest} 
[TP
  [NP
    [someone, roof]
  ]
  [T$'$
    [T, name=T]
    [VP
      [V$'$
        [\subnode{V1}{V}\\\subnode{eat}{eat}\\\ldots\\\ldots,name=V]
        [NP
          [{the pie}, roof]
        ]
      ]
    ]
  ]
]
\draw[->] let \p1=($(V1.north west)-(eat.west)$) in  
(T) to[in=-180, out=-75] ($(V.north west)+(0,-\y1-\pgfkeysvalueof{/pgf/inner
ysep})$);
\end{forest}

\end{document}

enter image description here

  • +1 Thanks ... but I should have said this explicitly in the question, I'd like to avoid the separate tikzpicture, if possible. Sorry for not making this clear. Do you know if it's possible? – Adam Liter Apr 28 '20 at 20:04
  • 1
    @AdamLiter Presumably it is not impossible but given the complexity of this answer by the author of the forest package I am afraid it may also not be easy. You can use \begin{pgfinterruptpicture} \begin{tikzpicture}[overlay,remember picture] \draw[->] (T) to[in=-180, out=-75] (eat); \end{tikzpicture} \end{pgfinterruptpicture} before \end{forest} but this is shabby IMHO. –  Apr 28 '20 at 20:12