我正在尝试重现此图表:
我在文档中读到tikz-qtree
,我需要将根的大小计算为级别距离的倍数,但我可以让它工作。到目前为止,我已经:
\documentclass[ twoside,openright,titlepage,numbers=noenddot,headinclude,%1headlines,% letterpaper a4paper
footinclude=true,cleardoublepage=empty,abstractoff, % <--- obsolete, remove (todo)
BCOR=5mm,paper=a4,fontsize=11pt,%11pt,a4paper,%
ngerman,american,%
]{scrreprt}
\usepackage{tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{arrows,decorations.markings,babel}
\begin{document}
\begin{tikzpicture}[every node/.style={align=left}]
\tikzset{
edge from parent/.style={
draw,edge from parent
path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
},
% level 2/.style={level distance=50pt},
% frontier/.style={distance from root=150pt} % Align leaf nodes
}
\Tree [.S
[.NP
[.Rolls-Royce ] [.Motor ] [.Cars ] [.Inc ]
]
[.VP
[.said ]
[.SBAR
[.NONE ]
[.S
[.NP [.it ] ]
[. VP
[.expects ]
[.S
[.NP
[.its ] [.U.S ] [. sales ]
]
[.VP
[. to ]
[. VP
[.remain ]
[.ADJP [. steady ] ]
[.PP
[.at ]
[.NP
[.QP [.about ] [.1200 ] ]
[.cars ]
]
]
]
]
]
]
]
]
]
]
\end{tikzpicture}
\end{document}
但结果是这样的(不适合页面):
我做错了什么?
到目前为止我尝试过以下建议:
答案1
我可以建议用 Forest 作为树和sidewaysfigure
位置吗?
首先,树:
\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges,linguistics]{forest}
\begin{document}
\begin{forest}
forked edges,
where n children=0{tier=terminus}{},
[S
[NP
[Rolls-Royce\\NNP]
[Motor\\NNP]
[Cars\\NNPS]
[Inc\\NNP]
]
[VP
[said\\VBD]
[SBAR
[-NONE-]
[S
[NP
[it\\PRP]
]
[VP
[expects\\VBZ]
[S
[NP
[its\\PRP\$]
[U.S\\NNP]
[sales\\NNS]
]
[VP
[to\\TO]
[VP
[remain\\VB]
[ADJP
[steady\\JJ]
]
[PP
[at\\IN]
[NP
[QP
[about\\IN]
[1200\\CD]
]
[cars\\NNS]
]
]
]
]
]
]
]
]
]
]
\end{forest}
\end{document}
即使侧向放置,树也太宽了。与其缩放它(这应该是最后的选择),不如使用较小的字体大小,例如和\scriptsize
通过更改来减少节点之间的空间s sep
。进行这些更改后,树将适合并且比简单缩放的树更清晰。如果您使用视觉尺寸的字体,情况尤其如此。
\documentclass[twoside,openright,titlepage,numbers=noenddot,headinclude, footinclude=true,cleardoublepage=empty,abstractoff,BCOR=5mm,paper=a4,fontsize=11pt,ngerman,american]{scrreprt}
\usepackage[edges,linguistics]{forest}
\usepackage{rotating}
\begin{document}
\begin{sidewaysfigure}
\centering
\scriptsize
\begin{forest}
forked edges,
where n children=0{tier=terminus}{},
for tree={
s sep'=1pt,
},
[S
[NP
[Rolls-Royce\\NNP]
[Motor\\NNP]
[Cars\\NNPS]
[Inc\\NNP]
]
[VP
[said\\VBD]
[SBAR
[-NONE-]
[S
[NP
[it\\PRP]
]
[VP
[expects\\VBZ]
[S
[NP
[its\\PRP\$]
[U.S\\NNP]
[sales\\NNS]
]
[VP
[to\\TO]
[VP
[remain\\VB]
[ADJP
[steady\\JJ]
]
[PP
[at\\IN]
[NP
[QP
[about\\IN]
[1200\\CD]
]
[cars\\NNS]
]
]
]
]
]
]
]
]
]
]
\end{forest}
\end{sidewaysfigure}
\end{document}
答案2
现在可以工作了!
\begin{figure}[h]
\resizebox{1.3\textwidth}{!}{%
\begin{tikzpicture}[every node/.style={align=center}]
\tikzset{
edge from parent/.style={
draw,edge from parent
path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
},
frontier/.style={distance from root=350pt} % Align leaf nodes
}
\Tree [.S
[.NP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS Inc\\NNP ]
[.VP said\\VBD
[.SBAR -NONE-
[.S
[.NP it\\PRP ]
[. VP expects\\VBZ
[.S
[.NP its\\PRP\$ U.S\\NNP sales\\NNS ]
[.VP to\\TO
[.VP remain\\VB
[.ADJP steady\\JJ ]
[.PP at\\IN
[.NP
[.QP about\\IN 1200\\CD ]
cars\\NNS
]
]
]
]
]
]
]
]
]
]
\end{tikzpicture}
}
\end{figure}
问题是将叶子添加为节点,如下所示:
[.NP [.Rolls-Royce ] [.Motor ] [.Cars ] [.Inc ] ]
% The correct way
[.NP Rolls-Royce Motor Cars Inc ]
更新
按照建议疾病控制与预防中心我做了一些调整:
- 已移除
resizebox
- 将字体大小减小至
tiny
- 减少内部边缘之间的距离
代码及结果:
\begin{figure}[h]
\tiny
\begin{tikzpicture}[every node/.style={align=center}]
\tikzset{
edge from parent/.style={
draw,edge from parent
path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
},
frontier/.style={distance from root=208pt}, % Align leaf nodes
level 1+/.style={level distance=18pt} % Distance between levels
}
\Tree [.S
[.NP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS Inc\\NNP ]
[.VP said\\VBD
[.SBAR -NONE-
[.S
[.NP it\\PRP ]
[. VP expects\\VBZ
[.S
[.NP its\\PRP\$ U.S\\NNP sales\\NNS ]
[.VP to\\TO
[.VP remain\\VB
[.ADJP steady\\JJ ]
[.PP at\\IN
[.NP
[.QP about\\IN 1200\\CD ]
cars\\NNS
]
]
]
]
]
]
]
]
]
]
\end{tikzpicture}
\end{figure}
更新 #2
我又做了一点小改动,让它看起来更像原版。叶子None
应该在第 3 级,而不是与句子的其余部分对齐。为此,唯一需要做的更改是:
[.SBAR [.none ]
% instead of
[.SBAR NONE
结果: