5

I want to draw the following Word Grammar diagram with tikz/forest: enter image description here

I am a great fan of forestand would like to have a style for such graphs, but I think this is non-trivial/impossible for this type of diagrams since the tree nodes are split into several instances (for instance: children, children', and children''). So what I would do is to use a table, put text in boxes into it and draw the connectors by explicit commands. Or is there a more "stylish" way to do this?

5

An idea is to signal split nodes using nodes with empty content. More precisely, style wg is defined to fill the content of an empty node with the content of its parent. Also, it appends a ' to the parents content.

To make drawing of dependency arrows easier, nodes are given names based on their content.

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\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,
    }{},
  },
}
\tikzset{deparrow/.style={-Latex,blue}}
\begin{document}
\begin{forest}
  wg
  [were
    [children
      [
        [small]
        []
      ]
    ]
    [
      []
    ]
    [playing
      [
        []
        [outside]
      ]
    ]
  ]
  \draw[deparrow] (were'') to[out=west, in=north] (children'');
  \draw[deparrow] (children') to[out=west, in=north] (small);
  \draw[deparrow] (were') to[out=60, in=120] (playing'');
  \draw[deparrow] (playing'') to[out=220, in=east] (children');
  \draw[deparrow] (playing') to[out=east, in=north] (outside);
\end{forest}
\end{document}
  • I now tried to do a simplified version of the diagram and noticed that one could draw most of the arrows automatically. It would be great if you could have a look at the new question as well: tex.stackexchange.com/questions/256651/… Thanks a lot! – Stefan Müller Jul 23 '15 at 11:37

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.