3

I have the following figure and want to prettify it. enter image description here

The problem is that the dashed lines cross the topmost VP node. I tried to use a coordinate grid in order to find out what arguments I could pass to \draw, but since all of the VP trees are independent forest figures, the usual code to draw a grid in the tikz picture did not work. So: how can I get the dashed lines right? How is this done in general?

\documentclass{article}                          


\usepackage{forest}

\usetikzlibrary{tikzmark}

% compile with texlive 2013

% draw a grid for getting the coordinates
%\usepackage{tikz-grid}


\newcommand{\menge}[1]{%
\mbox{%
$%
\left\{%
\ignorespaces#1%
\right\}%
$%
%\\[-1.5mm]
}%
}

\forestset{.style={for tree={parent anchor=south, child anchor=north,align=center,base=top}}}


\begin{document}

\noindent
\menge{%
\forestset{begin draw/.code={\begin{tikzpicture}[baseline=(current bounding box.center)]}}
\hspace{1em}
\begin{forest}
[VP
        [NP$\downarrow$]
        [\subnode{vp1b}{VP}]]
\end{forest}
\hspace{1em}
\begin{forest}
[VP
        [NP$\downarrow$]
        [\subnode{vp2b}{VP}]]
\end{forest}
\hspace{1em}
\begin{forest}
[VP
        [NP$\downarrow$]
        [\subnode{vp3b}{VP}]]
\end{forest}
\hspace{1em}
\begin{forest}
[VP
        [NP$\downarrow$]
        [\subnode{vp4b}{VP}]]
\end{forest}
\hspace{1em}
\begin{forest}
[VP
        [\subnode{vprep}{VP}
                [$\epsilon$]
                [zu reparieren]]
        [\subnode{vpversprochen}{VP}
                [$\epsilon$]
                [versprochen]]]
\end{forest}
\begin{tikzpicture}[overlay,remember picture,out=-90,in=90,dashed]
\draw (vp1b) to (vpversprochen);
\draw (vp2b) to (vpversprochen);
\draw (vp3b) to (vprep);
\draw (vp4b) to (vprep);
\end{tikzpicture}
}


\end{document}
  • 2
    If you draw them as one forest with phantom root, you can use tikz+ within the tree which might be easier. But something has to give here: either things are going to overlap or I guess the spacing between the last two trees has to increase. A mock-up of how you'd like it to look would help here since we don't know what would be acceptable within your specific discipline. (The existing answer seems to qualify as successfully prettified, for instance. Certainly it is clearer. But I understand that's not the only constraint here.) – cfr Mar 3 '16 at 13:27
3

I think the only way to do this is to either going to be to use some very sophisticated automatic code along the lines of the graph drawing stuff (but don't ask me how you could combine that with Forest or even use it to draw non-graph-like stuff) or to specify what you want quite precisely. This is easier if you put everything in one environment so you don't need to mess around with tikzmark. For example:

\documentclass{article}
\usepackage{forest}
\useforestlibrary{linguistics}
\usetikzlibrary{calc}
\newcommand{\menge}[1]{%
  \mbox{%
    $%
    \left\{%
    \ignorespaces#1%
    \right\}%
    $%
  }%
}
\forestset{% the .style hack was never supported and no longer works
  default preamble={%
    for tree={%
      sn edges,
      align=center,
      base=top,
    }
  }
}
\makeatletter
\newcommand*\ignoreme{\pgf@relevantforpicturesizefalse}
\makeatother
\begin{document}
\noindent
\menge{%
  \begin{forest}
    [, phantom, for children={if n'=1{before computing xy={l=0pt, s*=1.25}}{}}
      [VP
        [NP$\downarrow$]
        [VP, tikz+={\ignoreme\draw [densely dashed] ([yshift=2.5pt].south) [out=-75, in=-125] to ($(!u.north)!3/4!(!un.north)$) [out=55,in=90] to (!rll.north); }]
      ]
      [VP
        [NP$\downarrow$]
        [VP, tikz+={\draw [densely dashed] ([yshift=2.5pt].south) [out=-90, in=180] to ++(20mm,-15mm) [out=0, in=-90] to ($(!unn.north)!.7!(!unnn1.north)$) [out=90, in=180] to ++(3.5mm,5mm) [out=0, in=90] to (!rl1.north); }]
      ]
      [VP
        [NP$\downarrow$]
        [VP, tikz+={\draw [densely dashed] ([yshift=2.5pt].south) [out=-90, in=180] to ++(10mm,-10mm) [out=0, in=-90] to ($(!un.north)!.6!(!unn1.north)$) [out=90, in=180] to ++(5mm,7.5mm) [out=0, in=90] to (!rl1.north); }]
      ]
      [VP
        [NP$\downarrow$]
        [VP, tikz+={\draw [densely dashed] ([yshift=2.5pt].south) [out=-90, in=-105] to ($(!u.north)!1/3!(!un.north)$) [out=75,in=90] to (!rll.north); }]
      ]
      [VP
        [VP
          [$\epsilon$]
          [zu reparieren]
        ]
        [VP, baseline
          [$\epsilon$]
          [versprochen]
        ]
      ]
    ]
  \end{forest}
}
\end{document}

hand-drawn curves

for children={if n'=1{before computing xy={l=0pt, s*=1.25}}{}}

This adjusts the relative position of the last child by zeroing its distance from the phantom root and increasing its distance from its sibling. This is delayed because otherwise Forest will undo any changes when packing the tree.

\ignoreme

is required because the construction of the curves otherwise results in an enormous bounding box, which probably isn't what you want. To see what it does, just delete it from the tree and observe the results.

non-ignoring curve construction

Note that this code has been updated as your MWE cannot be compiled with the current version of Forest, so I had to change it just to reproduce the output you were getting. In particular, the .style thing is considered a hack which never worked correctly and is no longer working at all. default preamble is the supported (and working) alternative.

But obviously you can revert those parts of the code if need be. I assume the rest should work.

  • Thanks a lot! The most important thing I learned was the phantom node to put everything into the same environment. Could you maybe comment in the code on what the other stuff is doing? The for children? The \ignoreme. And also the paths. And how do you arrive at them. Is this just trial and error? – Stefan Müller Mar 4 '16 at 8:32
  • Please see edit. The paths are just trial and error. – cfr Mar 4 '16 at 13:30
  • Thanks a lot! I guess I will need another three years to fully master this ... – Stefan Müller Mar 4 '16 at 16:56
  • 1
    Even Forest is overwhelming. As for PGF/TikZ.... 3 years sounds pretty good to me. I think it will take me closer to 30, if I manage to dodge the wild rhinos that long ;). Note that you could use this kind of path with your original marks. You'd maybe need to add more marks to get the positioning, though. – cfr Mar 4 '16 at 20:25
  • I added this to my code: the following line is ignored for space computation due to \ignoreme the first VP node at the baseline is connected to a place between the dominating vp !u.north and the node to the left of it !un.north (the second VP node on the second line). 3/4 specifies the position between these nodes. It is more to the second VP. From there we go to rll, which is the root node's (r) last child's (l) last child (l). Since the root node is our phantom node, the rll node is the last VP in the second row. – Stefan Müller Mar 9 '16 at 9:48
4

Would this version work for you?

Output

enter image description here

Code snippet

\begin{tikzpicture}[overlay,remember picture,dashed, rounded corners=2mm]
\draw (vp1b) |- ++(.5,-1) |- ++ (5,3) -| (vpversprochen);
\draw (vp2b) |- ++(.5,-1) -- ++ (0,3);
\draw (vp3b) |- ++(.5,-1) |- ++ (3,2.5) -| (vprep);
\draw (vp4b) |- ++(.5,-1) -- ++ (0,2.5);
\end{tikzpicture}
  • Oh, this is very cool and it looks much nicer than what I know from the literature on these grammars. But I guess there is a certain tradition for drawing these trees. So it should be curvy lines and every dominance link has to be recognizable on its own. Question: how do you get the coordinates? Do you just guess or is there a systematic way of getting them? – Stefan Müller Mar 3 '16 at 9:11
  • @StefanMüller Those are relative coordinates (indicated by the ++). Basically ++(.5,-1) means "go 1 down and half to the right from the current point". They are hard coordinates, so I had to test them yes. If you do this kind of graph a lot, and they are all different, it might not be the best solution though. I have no problem with the curve as you used them but your graph isn't very suited to have those lines because they overlap everything. If you could place the smaller trees above the last one, for example, maybe it would make things easier. – Alenanno Mar 3 '16 at 9:15
  • 1
    @StefanMüller What about this version? – Alenanno Mar 3 '16 at 9:18
  • Thanks! Rearranging the trees is not an option since this is a set of trees. It has to be in these brackets. I guess I have to fine tune with controls, but I do not know how to get the coordinates. – Stefan Müller Mar 3 '16 at 9:29
  • 1
    @StefanMüller I see but the example in the book has some differences: there is one tree only and the spacing is bigger so that allows for a nice curved line. Yours has multiple trees and all of them are close together. Would you have perhaps some cases that look similar to yours and see how they solve it? It might help to give you an idea because I'm sure someone else has encountered your problem before. – Alenanno Mar 3 '16 at 9:43

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.