Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried several approaches, but none of them worked... Here is my tree code:

\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}

and here is how it looks like:

enter image description here

I want it to be narrower, i.e., pushing together the siblings at level one so there is no free space between the branches - or at least a bit less space...

share|improve this question
    
You have to watch for the space between 24 and 497. That is the actual space even if zero it. So you can go to negative numbers for a little tighter spacing. But then 444 branch will be overlapping. You might better reduce the sibling distance of the inbetween leaves. –  percusse Jul 18 '12 at 11:58

1 Answer 1

up vote 3 down vote accepted

There's no pretty way to do this, since tikz-qtree is designed to automatically make enough space for the complete width of the daughters of any particular node. As percusse points out in the comments, if you reduce the sibling distance, you end up with your 444 node overlapping the others. This is what needs to be avoided. We can do this by adding specific node sizes to certain nodes, and making the level 1 sibling distance negative. The one downside to this is that the bounding box of the picture is artificially large, so we need to manually adjust the bounding box.

I also removed the fixed text width which makes the trees look neater, and changed your \tikzstyle command for \tikzset. See Should \tikzset or \tikzstyle be used to define TikZ styles? for some discussion.

\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}

output of code

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.