我使用斯坦福解析器建立了樹(黑色組件)。但是,它無法導出圖表,所以我不得不截取螢幕截圖。然後,我必須向該圖表添加帶有該標籤的兩個新的彩色行。
顯然,當將其作為 JPG 導入乳膠中時,列印時會得到非常糟糕的結果。任何人都可以幫助或提供有關如何重現該圖或其一部分以及我應該使用什麼來實現此目的的提示嗎?
答案1
這是使用該套件在 LaTeX 中建立樹的一種方法forest
:
\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
tier/.wrap pgfmath arg={tier#1}{level()},
font=\sffamily
}
[ROOT, name=root
[SBARQ
[WHNP
[WDT
[Which]
]
[NP
[NN
[animal]
]
]
]
[SQ
[VBD
[was]
]
[RB
[not, name=not]
]
[VP
[VBN
[eaten, name=eaten]
]
]
]
[.
[?]
]
]
]
\draw [ultra thick, blue, -{Triangle[]}] (root.south east) [bend left=65] to node [pos=.25, right, fill=blue, font=\sffamily\footnotesize, text=white, inner sep=1pt, xshift=5pt] {ROOT} (eaten.north east) ;
\draw [ultra thick, red, -{Triangle[]}] (eaten.west) [bend left] to node [pos=.25, left, fill=red, font=\sffamily\footnotesize, text=white, inner sep=1pt, xshift=-5pt] {NEG} (not) ;
\end{forest}
\end{document}
答案2
由於 cfr 提供了一個很好的套件解決方案forest
,這裡有一個 Tikz 解決方案。
輸出
程式碼
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,calc,arrows.meta,positioning,bending}
\tikzset{
edge from parent/.style={draw, gray},
coln/.style={scale=0.6,inner sep=2pt, outer sep=0mm,draw=none,fill=#1, text=white},
>=latex,
}
\begin{document}
\begin{tikzpicture}[
level/.style={level distance=8mm},
level 1/.style={sibling distance=25mm},
level 3/.style={sibling distance=10mm},
font=\sffamily
]
\node (root) {ROOT}
child {node {SBARQ}
child {node {WHNP}
child {node {WDT}
child {node {Which}
}
}
child {node {NP}
child {node {NN}
child {node {animal}
}
}
}
}
child {node {SQ}
child {node {VBD}
child {node {was}
}}
child {node {RB}
child {node (not) {not}
}}
child {node {VP}
child {node {VBN}
child {node (eat) {eaten}
}}
}
}
child[sibling distance=18mm] {node {.}
child {node {?}
}
}
};
\draw[thick, blue!60!black] (root.east)
edge[out=-10,in=45,->,looseness=1.4] node [midway,right,xshift=.3em,coln=blue!55] {Root}
($(eat.north east)+(-1mm,-1mm)$);
\draw[thick, red] (eat.west)
edge[out=180,in=270,->] node [midway,left,xshift=-.3em,coln=red!60] {NEG}
(not.south);
\end{tikzpicture}
\end{document}