How can I reduce the overall size of trees drawn by tikz-qtree
? I've got a huge parse tree that doesn't even try to fit on one page. I'd like to either resize the full tree or tweak the placing algorithm to make the tree more dense.
Put the entire tree in a \resizebox
from the graphicx
package. Here's what the graphics guide has to say about this command:
\resizebox{⟨h-length⟩}{⟨v-length⟩}{⟨text⟩}
Scale text so that the width is h-length. If
!
is used as either length argument, the other argument is used to determine a scale factor that is used in both directions. Normally v-length refers to the height of the box, but in the star form, it refers to the ‘height + depth’. As normal for LaTeX2ε box length arguments,\height
,\width
,\totalheight
,\depth
may be used to refer to the original size of the box.
\bigskip
, \newpage
, \hfill
, and \hspace{0pt}
are just used to make the example spacing look nicer.
Note that in order for the vertical resizing to work, you need to put the \Tree
in a tikzpicture
environment.
And of course, you can also just use 5cm
as a length; I only included lengths related to typesetting dimensions in my examples.
\documentclass[12pt]{article}
\usepackage[a6paper,showframe]{geometry}% just to demonstrate the effects
\usepackage{graphicx}
\usepackage{tikz-qtree}
\begin{document}
\setlength{\parindent}{0cm}% get rid of paragraph indents for this example
%
% HORIZONTAL RESIZING FOR WIDE TREES
%
Original Size:
\Tree[.Top A B C D E F G H I J K L M N O P ]
\bigskip
Full linewidth:
\resizebox{\linewidth}{!}{%
\Tree[.Top A B C D E F G H I J K L M N O P ]
}
\bigskip
Linewidth minus 1cm:
\resizebox{\dimexpr\linewidth-1cm}{!}{%
\Tree[.Top A B C D E F G H I J K L M N O P ]
}
\bigskip
Half linewidth:
\resizebox{.5\linewidth}{!}{%
\Tree[.Top A B C D E F G H I J K L M N O P ]
}
\bigskip
%
% VERTICAL RESIZING FOR TALL TREES
%
Page 2: original size
Page 3: textheight, textheight minus 1cm, half textheight
\newpage
\begin{tikzpicture}\Tree[.A [.B [.C [.D [.E [.F [.G [.H [.I [.J [.K [.L [.M [.N [.O [. P ]]]]]]]]]]]]]]]]\end{tikzpicture}
\newpage
\hfill
\resizebox{!}{\textheight}{\begin{tikzpicture}
\Tree[.A [.B [.C [.D [.E [.F [.G [.H [.I [.J [.K [.L [.M [.N [.O [. P ]]]]]]]]]]]]]]]]
\end{tikzpicture}}
\hfill
\resizebox{!}{\dimexpr\textheight-1cm}{\begin{tikzpicture}
\Tree[.A [.B [.C [.D [.E [.F [.G [.H [.I [.J [.K [.L [.M [.N [.O [. P ]]]]]]]]]]]]]]]]
\end{tikzpicture}}
\hfill
\resizebox{!}{.5\textheight}{\begin{tikzpicture}
\Tree[.A [.B [.C [.D [.E [.F [.G [.H [.I [.J [.K [.L [.M [.N [.O [. P ]]]]]]]]]]]]]]]]
\end{tikzpicture}}
\hfill\hspace{0pt}
\end{document}
-
-
-
-
@doncherry Is it OK if I vote for duplicate to this question tex.stackexchange.com/questions/39944/… pointing to this? It's been lingering for ages... – percusse Oct 24 '12 at 23:22
-
2No, this isn't really a duplicate because the size of the other tree would turn into microtype (in the Cold War spy sense) if you shrunk it using resize box. Also, shrinking in this way is always a bit of a compromise. @Tass might also consider using the
pdflscape
package to put the tree on a landscape page within a regular document. – Alan Munn Oct 25 '12 at 1:20