我尝试了几种方法,但都没有用...这是我的树代码:
\begin{figure}[bh!]
\centering
\begin{tikzpicture}[ level distance=1cm, growth parent anchor=east, grow=right,scale=0.78,
level distance=1cm,
]
\tikzstyle{every node}=[font=\footnotesize, text width=5mm,anchor=east]
\Tree[.{0} [.{1} [.{1} [.{1} [.{1} [.{2} [.{7} [.{9} [.{4} [.{33} ] [.{474} ] ] [.{478} ] ] [.{487} ] ] [.{494} ] ] [.{496} ] ] [.{497} ] ] [.{498} ] ] [.{499} ] ] [.{4} [.{13} [.{4} [.{4} [.{7} [.{25} [.{9} [.{120} [.{314} ] [.{314} ] ] [.{434} ] ] [.{443} ] ] [.{468} ] ] [.{475} ] ] [.{479} ] ] [.{483} ] ] [.{496} ] ] [.{1} [.{2} [.{18} [.{39} [.{2} [.{55} [.{56} [.{327} ] [.{327} ] ] [.{383} ] ] [.{438} ] ] [.{440} ] ] [.{479} ] ] [.{497} ] ] [.{499} ] ] [.{3} [.{10} [.{2} [.{3} [.{6} [.{8} [.{7} [.{16} [.{32} ] [.{445} ] ] [.{461} ] ] [.{468} ] ] [.{476} ] ] [.{482} ] ] [.{485} ] ] [.{487} ] ] [.{497} ] ] [.{6} [.{9} [.{7} [.{1} [.{3} [.{3} [.{9} [.{14} [.{24} ] [.{448} ] ] [.{462} ] ] [.{471} ] ] [.{474} ] ] [.{477} ] ] [.{478} ] ] [.{485} ] ] [.{494} ] ] [.{444} [.{56} ] [.{56} ] ] ]
\end{tikzpicture}
\end{figure}
它看起来是这样的:
我希望它更窄一些,也就是说,将第一级的兄弟姐妹推到一起,这样分支之间就没有自由空间了 - 或者至少空间小一点......
答案1
没有很好的方法可以做到这一点,因为tikz-qtree
它被设计为自动为任何特定节点的子节点的完整宽度留出足够的空间。正如 percusse 在评论中指出的那样,如果你减少兄弟节点距离,你最终会导致 444 节点与其他节点重叠。这是需要避免的。我们可以通过向某些节点添加特定节点大小并使 1 级兄弟节点距离为负来实现这一点。这样做的一个缺点是图片的边界框人为地大,所以我们需要手动调整边界框。
我还删除了 fixed text width
,这使得树木看起来更整洁,并将您的\tikzstyle
命令更改为\tikzset
。请参阅应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?进行一些讨论。
\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[level distance=1cm, growth parent anchor=east,
grow=right,scale=0.78,level distance=1cm,
level 1/.style={sibling distance=-2.25cm}
]
\tikzset{every node/.style={font=\footnotesize,anchor=east}}
\useasboundingbox (-.5cm,-9cm) rectangle (10cm,6cm);
\Tree[.{0} [.{1} [.{1} [.{1} [.{1} [.{2} [.{7} [.{9} [.{4} [.{33} ] [.{474} ] ] [.{478} ] ] [.{487} ] ] [.{494} ] ] [.{496} ] ] [.{497} ] ] [.{498} ] ] [.{499} ] ]
[.\node[minimum height=2.25cm] (4) {4}; [.{13} [.{4} [.{4} [.{7} [.{25} [.{9} [.{120} [.{314} ] [.{314} ] ] [.{434} ] ] [.{443} ] ] [.{468} ] ] [.{475} ] ] [.{479} ] ] [.{483} ] ] [.{496} ] ]
[.\node[minimum height=1.5cm] (1) {1}; [.{2} [.{18} [.{39} [.{2} [.{55} [.{56} [.{327} ] [.{327} ] ] [.{383} ] ] [.{438} ] ] [.{440} ] ] [.{479} ] ] [.{497} ] ] [.{499} ] ]
[.{3} [.{10} [.{2} [.{3} [.{6} [.{8} [.{7} [.{16} [.{32} ] [.{445} ] ] [.{461} ] ] [.{468} ] ] [.{476} ] ] [.{482} ] ] [.{485} ] ] [.{487} ] ] [.{497} ] ]
[.{6} [.{9} [.{7} [.{1} [.{3} [.{3} [.{9} [.{14} [.{24} ] [.{448} ] ] [.{462} ] ] [.{471} ] ] [.{474} ] ] [.{477} ] ] [.{478} ] ] [.{485} ] ] [.{494} ] ]
[.\node[minimum height=6.5cm] (444) {444}; [.{56} ] [.{56} ] ] ]
\end{tikzpicture}
\end{document}