[Tex/LaTex] Typesetting Dependency Grammar trees

forestlinguisticstrees

I try to typeset dependency trees:

enter image description here

Is there a package that does this? It should be compatible with xelatex, i.e. not be based on pstricks. I could not find anything with google or on CTAN. If there is no package, I would try to do it with forest, but this seems not to be straightforward. How can this be done straightforwardly?

Edit: I found (half of) a solution in forest:

\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}{}}},
}


\begin{document}

\begin{forest}
dg edges
[V
  [N
    [D [the] ]
     [child] ]
  [reads]
  [N
    [D [a] ]
    [book] ] ]
\end{forest}


\end{document}

enter image description here

This gets the dotted lines right and also aligns the words at the baseline. However, the alignment of the nodes is not right. If I could have N exactly on top of book and V above reads and do this in the style definition, this would be the preferred solution. Is there a way to do this in forest?

Best Answer

This is an attempt where tikz tree is used. To align the text at the bottom a dfont style is defined.

enter image description here

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,calc}
\begin{document}
\tikzset{ 
treenode/.style = {inner sep=0pt, outer sep=2pt, font=\sffamily},
edge from parent/.style={draw, edge from parent path=
    {(\tikzparentnode.south) -- (\tikzchildnode.north)}},
dfont/.style={dashed,font=\vphantom{Ag},anchor=north}  % to align the text at the bottom
}

\begin{tikzpicture}
 [
% Children and edges style
    level distance=1cm,
    level 1/.style={sibling distance=2cm},
    level 2/.style={sibling distance=2cm},
    level 3/.style={sibling distance=3.5cm},
    level 4/.style={sibling distance=6cm},
    level 5/.style={sibling distance=3cm}
    ]
%% Draw events and edges
 \node (g) [treenode] {are}
            child {node[treenode] (a) {We}}    % left
            child {node[treenode] (b) {trying} % right  
                     child[missing]
            child {node[treenode] (c) {to}
                     child[missing]
            child {node[treenode](d) {understand}
                     child[missing]
            child {node[treenode] (e) {difference}    
                   child {node[treenode](f){the}}
                   child[missing]}
}
}
};  
\node (a1) at ($(a)+(0,-6)$){};
\draw[dfont] (a) -- (a|-a1)node[]{We};
\draw[dfont] (g) -- (g|-a1)node[]{are};
\draw[dfont] (b) -- (b|-a1)node[]{trying};
\draw[dfont] (c) -- (c|-a1)node[]{to};
\draw[dfont] (d) -- (d|-a1)node[]{understand};
\draw[dfont] (f) -- (f|-a1)node[]{the};
\draw[dfont] (e) -- (e|-a1)node[]{difference.};
\end{tikzpicture}
\end{document}
Related Question