2

I wrote a style for forest that can be used to connect a tree node with its sibling to the left and to the right. This works very nice for cases like the one below.

enter image description here

Now I want to connect two nodes at the toplevel (basically two full trees). I introduced a node on top of the two nodes and declared it a phantom node. For reasons I do not understand the connection between the two daughters is not drawn:

enter image description here

If I replace the phantom node by a real node, everything is fine: enter image description here

How can I get rid of the top-most V node and keep the rest?

\documentclass{article}

\usepackage{forest}


\forestset{dg edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom},
                 where n children=0{tier=word,edge=dotted,calign with current edge}{}
                },
dg junction/.style={edge path={\noexpand\path[\forestoption{edge}]
(!p.east)--(!.west) (.east)--(!n.west)\forestoption{edge label};}}    }

\begin{document}

\begin{forest}
dg edges
[V %,phantom
  [V, l sep+=2ex, name=v1
    [N,name=n1 [Robin]]
    [came]
    [Part [in] ] ]
  [Conj,dg junction [and]]
  [V, l sep+=2ex, name=v2 [found]
     [N 
       [Det [a]]
       [chair]]
     [P, name=p [in]
        [N 
          [Det [thirty]]
          [seconds]]]
]]
\draw (v2.south)--(n1.north)
      (v1.south)--(p.north);
\end{forest}

\end{document}

Edit:

The following happens with \phantom{V}:

\documentclass{article}

\usepackage{forest}


\forestset{dg edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom},
                 where n children=0{tier=word,edge=dotted,calign with current edge}{}
                },
dg junction/.style={edge path={\noexpand\path[\forestoption{edge}]
(!p.east)--(!.west) (.east)--(!n.west)\forestoption{edge label};}}    }

\begin{document}
bla, bla, bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla,    bla,bla, bla,bla, bla,
\begin{forest}
dg edges
[\phantom{V}
  [V, l sep+=2ex, name=v1
    [N,name=n1 [Robin]]
    [came]
    [Part [in] ] ]
  [Conj,dg junction [and]]
  [V, l sep+=2ex, name=v2 [found]
     [N 
       [Det [a]]
       [chair]]
     [P, name=p [in]
        [N 
          [Det [thirty]]
          [seconds]]]
]]
\draw (v2.south)--(n1.north)
      (v1.south)--(p.north);
\end{forest}

\end{document}

If I add no edgeto the V nodes, the edges are gone, but there is still the space of the phantom node. The figure looks like below except that the edges at the top are hidden:

enter image description here

  • 1
    Use \phantom{V} at the top node. – Jesse Jan 10 '15 at 14:44
  • Thanks. I did this and added two no edge declarations to the V daughters. It works, but the size of the node is still added to the tree, whereas the node with ,phantom declaration does not use any space. – Stefan Müller Jan 10 '15 at 14:53
  • How about \phantom{V},phantom? – Jesse Jan 10 '15 at 14:58
  • Unfortunately this does not work. The connection between the nodes disappears again. – Stefan Müller Jan 10 '15 at 15:04
  • 2
    Don't use edge path. Use the tikz key. No edge is drawn because the parent is a phantom, so the contents of edge path is not executed. If you use tikz (without the \forestoption bits which you don't need), it will work fine. – cfr Jan 10 '15 at 21:50
4

edge path has no effect because the parent is a phantom, which effectively implies no edge for the children. Use the tikz key instead:

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

\usepackage{forest}


\forestset{
  dg edges/.style={
    for tree={
      parent anchor=south,
      child anchor=north,
      align=center,base=bottom},
    where n children=0{
      tier=word,
      edge=dotted,
      calign with
      current edge
    }{}
  },
  dg junction/.style={
    tikz={
      \path[\forestoption{edge}] (!p.east)--(!.west) (.east)--(!n.west);
    },
    % no edge,% uncomment if you never want edges with this style
  }
}

\begin{document}

\begin{forest}
  dg edges
  [,phantom
    [V, l sep+=2ex, name=v1
      [N,name=n1 [Robin]]
      [came]
      [Part [in] ] ]
    [Conj,dg junction [and]]
    [V, l sep+=2ex, name=v2 [found]
       [N
         [Det [a]]
         [chair]]
       [P, name=p [in]
          [N
            [Det [thirty]]
            [seconds]]]
  ]]
  \draw (v2.south)--(n1.north)
        (v1.south)--(p.north);
\end{forest}

\end{document}

tikz path

As Stefan Müller points out in the discussion on the question, to use the same style when the parent is not a phantom, you need to add an explicit no edge unless, of course, you want both the tikz and the edge paths to be drawn.

  • But you shoud add the no edge option to the dg junction style as well. Thanks a lot! This forest stuff is so cool! It is really great in comparison to what we linguists did the decades before ... – Stefan Müller Jan 11 '15 at 20:16
  • @StefanMüller Thanks. I've added it as a comment in the code. I guess for this use nobody would want it without that, but who knows? – cfr Jan 11 '15 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.