Composición tipográfica de árboles gramaticales de dependencia

Composición tipográfica de árboles gramaticales de dependencia

Intento componer árboles de dependencia:

ingrese la descripción de la imagen aquí

¿Existe algún paquete que haga esto? Debería ser compatible con xelatex, es decir, no basarse en pstricks. No pude encontrar nada en google ni en CTAN. Si no hay ningún paquete, intentaría hacerlo con forest, pero parece que esto no es sencillo. ¿Cómo se puede hacer esto de manera sencilla?

Editar:Encontré (la mitad de) una solución en 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}

ingrese la descripción de la imagen aquí

Esto hace que las líneas de puntos sean correctas y también alinea las palabras en la línea de base. Sin embargo, la alineación de los nodos no es la correcta. Si pudiera tener N exactamente encima del libro y V arriba y hacer esto en la definición de estilo, esta sería la solución preferida. ¿Hay alguna manera de hacer esto en forest?

Respuesta1

Este es un intento donde tikz treese utiliza. Para alinear el texto en la parte inferior dfontse define un estilo.

ingrese la descripción de la imagen aquí

Código

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

Respuesta2

Un poco torpe, pero muestra cómo especificar una función de crecimiento personalizada y una forma astuta de duplicar las palabras en la parte inferior. Tomé un par de estilos de la respuesta de Jesse:

\documentclass[tikz, border=5]{standalone}
% An (incomplete) growth function
\makeatletter
\def\tikz@grow@tree{%
  \tikzset{shift=(270:\tikzleveldistance)}%
  \ifcase\tikznumberofchildren%
  \or     
  \or
     \tikzset{shift=(0:{(\tikznumberofcurrentchild-1)*\tikzsiblingdistance})}
  \else%
     \tikzset{shift=(0:{(\tikznumberofcurrentchild-1-\tikznumberofchildren+2)*\tikzsiblingdistance})}
  \fi
}

\tikzset{%
  dependency tree/.code={\let\tikz@grow=\tikz@grow@tree},
  leaf level/.store in=\tikzleaflevel,
  tree node/.style={inner sep=0pt, outer sep=2pt, font=\sffamily},
     edge from parent/.style={draw, edge from parent path={(\tikzparentnode.south) -- (\tikzchildnode.north)}},
  leaf/.style={level distance=(\tikzleaflevel-\the\tikztreelevel)*1cm,
    edge from parent/.append style={dashed}, execute at begin node=\strut}
}
\def\wordnode#1{ node [tree node] {#1} child [leaf] { node {#1} } }

\begin{document}
\begin{tikzpicture}[level distance=1cm,dependency tree, leaf level=8]

 \node [tree node] 
   {are}
   child { \wordnode{We} }    
   child [leaf] { node {are} }
   child { \wordnode {trying} 
     child { \wordnode {to} 
       child  { \wordnode{understand} 
         child [sibling distance=3cm] { \wordnode{difference}           
           child [xscale=-1, sibling distance=1.5cm] { \wordnode{the}
    }}}}};  

\end{tikzpicture}
\end{document}

ingrese la descripción de la imagen aquí

Respuesta3

La calign with current edgeopción funcionó:

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


\begin{document}

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


\end{document}

ingrese la descripción de la imagen aquí

información relacionada