![对齐树叶](https://linux22.com/image/287061/%E5%AF%B9%E9%BD%90%E6%A0%91%E5%8F%B6.png)
我有以下树,其中最左边的叶子不同步:
\documentclass{minimal}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\tikzset{level 1+/.style={level distance=3\baselineskip}}
\tikzset{level 2+/.style={level distance=2\baselineskip}}
\tikzset{frontier/.style={distance from root=8\baselineskip}}
\tikzset{every tree node/.style={align=left, anchor=north}}
\tikzset{every leaf node/.append style={text depth=0pt}}
\Tree[.S
[.NP er\\he ]
[.NP
[.Det das\\the ]
[.N Buch\\book ] ]
[.NP
[.Det der\\the ]
[.N Frau\\woman ] ]
[.V gibt\\gives ] ]
\end{tikzpicture}
\end{document}
我跟着
将几棵树与基线对齐
并添加了\tikzset{every leaf node/.append style={text depth=0pt}}
,但这没有任何效果。
答案1
如果你愿意使用强大的forest
包(内部使用 PGF/TikZ):
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
align=left,
base=bottom
},
where n children=0{tier=word}{}
[S
[NP [er\\he] ]
[NP
[Det [das\\the] ]
[N [Buch\\book] ]
]
[NP
[Det [der\\the] ]
[N [Frau\\woman] ]
]
[V [gibt\\gives] ]
]
\end{forest}
\end{document}
要使所有节点内容居中,请将 align=left 更改为 align=center(当然,这只能针对叶子节点或基于 oer 情况执行)。
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
align=center,
base=bottom
},
where n children=0{tier=word}{}
[S
[NP [er\\he] ]
[NP
[Det [das\\the] ]
[N [Buch\\book] ]
]
[NP
[Det [der\\the] ]
[N [Frau\\woman] ]
]
[V [gibt\\gives] ]
]
\end{forest}
\end{document}
base=bottom
事实上,这里不需要这个选项,因为所有的叶子都有两条线。