我使用 Stanford Parser 构建了树(黑色组件)。但是,它无法导出其图表,因此我不得不截取屏幕截图。然后,我必须在该图表中添加带有该标签的两个新的彩色行。
显然,当将其作为 JPG 导入到 latex 中时,打印时效果非常糟糕。有人能帮忙或提示如何重现此图或其中的一部分以及我应该使用什么来实现这一点吗?
答案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}