조판 종속성 문법 트리

조판 종속성 문법 트리

종속성 트리를 조판하려고 합니다.

여기에 이미지 설명을 입력하세요

이 작업을 수행하는 패키지가 있나요? 와 호환되어야 합니다 xelatex. 즉, 을 기반으로 하지 않아야 합니다 pstricks. Google이나 CTAN에서는 아무것도 찾을 수 없습니다. 패키지가 없으면 로 하려고 하는데 forest이게 쉽지 않은 것 같습니다. 이 작업을 어떻게 간단하게 수행할 수 있습니까?

편집하다:나는 다음에서 해결책을 찾았습니다 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}

여기에 이미지 설명을 입력하세요

이렇게 하면 점선이 올바르게 표시되고 기준선에 단어가 정렬됩니다. 그러나 노드의 정렬이 올바르지 않습니다. 책 위에 정확히 N을 두고 읽기 위에 V를 두고 스타일 정의에서 이 작업을 수행할 수 있다면 이것이 선호되는 솔루션이 될 것입니다. 에서 이 작업을 수행할 수 있는 방법이 있나요 forest?

답변1

이것은 사용되는 시도입니다 tikz tree. 하단의 텍스트를 정렬하기 위해 dfont스타일이 정의됩니다.

여기에 이미지 설명을 입력하세요

암호

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

답변2

약간 복잡하지만 사용자 정의 성장 함수를 지정하는 방법과 하단에 단어를 복제하는 교활한 방법을 보여줍니다. 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}

여기에 이미지 설명을 입력하세요

답변3

옵션 이 calign with current edge트릭을 수행했습니다.

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

여기에 이미지 설명을 입력하세요

관련 정보