# How can I make this tree shrink to fit standard page?

 \documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

\begin{tikzpicture}[grow=right, sloped]
\node[bag] {A-B-B}
child {
node[bag] {B}
child {
node[end] {}
}
child {
node[end] {}
}
}
child {
node[bag] {A}
child {
node[bag] {B}
child {
node[bag] {B}
child {
node[bag] {B}
child {
node[bag] {B}
}
}
}
}
child {
node[end] {}
}
};
\end{tikzpicture}

\end{document}

• What is a standard page where you are? Standard is as standard does and it doesn't the same here as it does there! One way is to use sidewaysfigure from the rotating package, for example, to rotate the tree. (Assuming it is too wide for portrait but not landscape.)
– cfr
Mar 14, 2016 at 1:44
• I just realised that you are using what look like huge sibling distances. Why? Ditto for level distances. And a width of 4em is pretty enormous if the content of the node is a single letter. Surely reducing these values is the obvious move here?
– cfr
Mar 14, 2016 at 1:45
• About - the size. 8x11? is standard? A4? About the spacing: noted that I can make it smaller. It is going to be a rather large tree, this is just a very small example to show the problem. Mar 14, 2016 at 2:58
• (1) 8x11 is standard nowhere than I know of. Maybe A4. Maybe not. Only you know what paper is standard where you are. For me, A4 is standard. When I lived in the States, US letter was standard. I mean: we can't tell you what size paper you have. (2) If you don't want to make it smaller, how are we supposed to make it fit if it doesn't? LaTeX is not a typographical Tardis and we cannot make it behave like one. If it doesn't fit, you have choices: make it smaller, use larger paper. What do you have in mind if not one of those?
– cfr
Mar 14, 2016 at 4:13
• I never meant I cannot make it smaller. I am only saying making my example smaller does not fix my problem, that this only shows what the problem is if you typeset it. Also 8x11ish.. is pretty close to US letter head. Mar 14, 2016 at 4:24

Your graph is to wide to be fit in text width. To solve this problem you have three possibilities:

• include graph in landscape page orientation

• redraw graph that it will grow down (below) instead to right

• make level distance smaller.

For the last possibilities is code below. In it I also slightly change nodes options and add (as temporary solution to see their borders) option draw. In preamble is also added package showframe which show page layout.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\usepackage{showframe}

\begin{document}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=2cm, sibling distance=3cm]
\tikzstyle{level 2}=[sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [draw, minimum width=2em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

\begin{tikzpicture}[grow=right, sloped]
\node[bag] {A-B-B}
child {
node[bag] {B}
child {
node[end] {}
}
child {
node[end] {}
}
}
child {
node[bag] {A}
child {
node[bag] {B}
child {
node[bag] {B}
child {
node[bag] {B}
child {
node[bag] {B}
}
}
}
}
child {
node[end] {}
}
};
\end{tikzpicture}

\end{document}


Of course, in real use you just omit all demo borders.