6

I got code for drawing dependency grammar trees (drawing complex dependency diagrams with tikz / forest). I now added labels to the dependency arrows, but this does not look nice, since the space between the arrows is not sufficent. Is there a way to get more space for all these arrows and their descriptions automatically? I think glaubst-dass, habe-ich and dass-habe have to be higher.

This is what I have:

enter image description here

\documentclass{article}

\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{deparrow/.style={-Latex}}%,blue}}


\forestset{
 wg/.style={
    for tree={
      no edge,
      draw,
      outer ysep=1pt,
    },
    copy label/.style={
      for children={
        if content={}{
            content/.pgfmath={content("!u")},
            calign with current,
            edge={draw,{-Triangle[open,reversed]}},
            copy label,
            !u.content/.pgfmath={content},
            !u.content+=',
        }{
          copy label,
        }
      }
    },
    delay={
      copy label,
      for tree={name/.pgfmath={content}},
    },
    for tree={content format={\strut\forestoption{content}}},
    where n children={0}{
      tier=word,
    }{},
  },
}


    \begin{document}
\begin{forest}
  wg
  [,phantom
   [wen]
   [glaubst]
   [du]
   [dass]
   [ich]
   [gesehen]
   [habe]
  ]
\draw[deparrow] ([xshift=-0pt]glaubst.north) to[out=north, in=north] node[above] {s}     ([xshift= 0pt]du.north);
\draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north] node[above] {c}     ([xshift=-3pt]dass.north);
\draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north] node[above] {c}     ([xshift= 3pt]habe.north);
\draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {r}     ([xshift= 0pt]gesehen.north);
\draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {s}     ([xshift= 0pt]ich.north);
%
\draw[deparrow] ([xshift= 0pt]gesehen.south) to[out=south, in=south] node[below] {x$<$o} ([xshift=-3pt]wen.south);
\draw[deparrow] ([xshift= 0pt]dass.south)    to[out=south, in=south] node[below] {x$<$}  ([xshift= 0pt]wen.south);
\draw[deparrow] ([xshift= 0pt]glaubst.south) to[out=south, in=south] node[below] {x$<$}  ([xshift= 3pt]wen.south);
\end{forest}

\end{document}
4

You can define controll points for the bezier curve which is, of course, not an automatic solution:

\draw[deparrow] ([xshift=-0pt]glaubst.north) .. controls +(up:6mm) and +(up:6mm) .. node[above] {s}  ([xshift= 0pt]du.north);
\draw[deparrow] ([xshift=-3pt]glaubst.north) .. controls +(up:12mm) and +(up:12mm) .. node[above] {c} ([xshift=-3pt]dass.north);
  • Thanks! There are so many options to control the behaviour of these arrows. I did not know the up option. I could imagine an automatic solution that is suboptimal: one could incremt the up-value. – Stefan Müller Sep 18 '15 at 13:49
3

An alternative is to increase the looseness of the curve, which allows you to keep the current syntax otherwise unaltered. For example:

...
  \draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north, looseness=1.2] node[above] {c}     ([xshift=-3pt]dass.north);
  \draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north, looseness=1.5] node[above] {c}     ([xshift= 3pt]habe.north);
...
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north, looseness=1.2] node[above] {s}     ([xshift= 0pt]ich.north);

will increase the looseness of the three curves in question:

space for labels

Complete code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{deparrow/.style={-Latex}}
\forestset{
 wg/.style={
    for tree={
      no edge,
      draw,
      outer ysep=1pt,
    },
    copy label/.style={
      for children={
        if content={}{
            content/.pgfmath={content("!u")},
            calign with current,
            edge={draw,{-Triangle[open,reversed]}},
            copy label,
            !u.content/.pgfmath={content},
            !u.content+=',
        }{
          copy label,
        }
      }
    },
    delay={
      copy label,
      for tree={name/.pgfmath={content}},
    },
    for tree={content format={\strut\forestoption{content}}},
    where n children={0}{
      tier=word,
    }{},
  },
}

\begin{document}
\begin{forest}
  wg
  [,phantom
   [wen]
   [glaubst]
   [du]
   [dass]
   [ich]
   [gesehen]
   [habe]
  ]
  \draw[deparrow] ([xshift=-0pt]glaubst.north) to[out=north, in=north] node[above] {s}     ([xshift= 0pt]du.north);
  \draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north, looseness=1.2] node[above] {c}     ([xshift=-3pt]dass.north);
  \draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north, looseness=1.5] node[above] {c}     ([xshift= 3pt]habe.north);
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {r}     ([xshift= 0pt]gesehen.north);
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north, looseness=1.2] node[above] {s}     ([xshift= 0pt]ich.north);
  \draw[deparrow] ([xshift= 0pt]gesehen.south) to[out=south, in=south] node[below] {x$<$o} ([xshift=-3pt]wen.south);
  \draw[deparrow] ([xshift= 0pt]dass.south)    to[out=south, in=south] node[below] {x$<$}  ([xshift= 0pt]wen.south);
  \draw[deparrow] ([xshift= 0pt]glaubst.south) to[out=south, in=south] node[below] {x$<$}  ([xshift= 3pt]wen.south);
\end{forest}

\end{document}

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.