# Reducing forest tree width without squashing

Apologies if this is a silly question - my first on stackexchange. I have built the tree below using the forest package. Unfortunately, the tree has got too "wide" for the page.

Is there a way to ask forest to put eg the pink set of boxes on a long line below the green boxes, so that the tree fits on the page? Or can you think of a way to typeset this graph so that it fits horizontally without looking too "squashed"?

Thanks!

\documentclass{article}

\usepackage{forest}
\usepackage{tikz}

%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}

\begin{document}

\begin{forest}
for tree={%
l sep=0.6cm,
s sep=0.8cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=green!30}  %Format everything below here as children
[Sub distributor
[Agent
[Customer] {\draw[->,dotted] () to[out=north,in=north west] (Company);}
[Installer]
[Installer]
]
[Agent]
]
[Sub distributor
[Agent]
[Agent]
]
]
[Distributor, for tree={child, fill=pink!50}
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
[Sub distributor]
]
]
\end{forest}

\end{document}

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 Feb 4 '15 at 8:28
• (I did not run an example.) Does option l=3cm help? It is illustrated at page 13 of the manual. – Symbol 1 Feb 4 '15 at 8:31
• Or grow our tree form left to right by grow=east. The point is to make the direction perpendicular to the text. – Symbol 1 Feb 4 '15 at 8:35

You can adjust the text width for nodes and also adjust the l ans s sep to bring the nodes closer. Adding further, swap the Sub distributor nodes. You have to modify the dotted arrow slightly though.

\documentclass{article}

\usepackage{forest}

%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}

\begin{document}

\begin{forest}
for tree={%
l sep=1cm,
s sep=0.1cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=green!30}  %Format everything below here as children
[Sub distributor
[Agent]
[Agent]
]
[Sub distributor,
[Agent,
[Customer] {\draw[->,dotted] () -- ++(-4cm,0) to[out=north,in=west] (Company);}
[Installer]
[Installer]
]
[Agent]
]
]
[Distributor, for tree={child, fill=pink!50}
[Sub distributor]
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
]
]
\end{forest}

\end{document}


I hope this is enough crunching to bring things inside the page ;-).

By using s=1cm in

[Company,s=1cm, name=Company,...


the horizontal separation between green and pink gangs can be adjusted to get

but it will again increase the total width (which is what we were trying to reduce!).

Shifting pinks to the left will give

\documentclass{article}

\usepackage{forest}

%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}

\begin{document}

\begin{forest}
for tree={%
l sep=1cm,
s sep=0.1cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=pink!50}
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
[Sub distributor]
]
[Distributor, for tree={child, fill=green!30}  %Format everything below here as children
[Sub distributor
[Agent]
[Agent]
]
[Sub distributor,
[Agent,
[Customer] {\draw[->,dotted] () --++(0,-1cm) -- ++(6.5cm,0) to[out=north,in=east] (Company);}
[Installer]
[Installer]
]
[Agent]
]
]
]
\end{forest}

\end{document}


As can be seen this doesn't improve much.

• Thanks for the suggestions - they were all really helpful! One last one if you don't mind - I think it would be more readable if the pink boxes lived in their own vertical space (not overlapping with the greens). Is there a way to create a "virtual divider" or shuffle all the pinks to the right? – David Feb 4 '15 at 11:26
• @David You can but it will make the tree wider again. (I'm assuming you meant 'horizontal' rather than 'vertical' since that's what moving them right would do.) – cfr Feb 4 '15 at 13:20
• @cfr Thanks for the correction, I did mean horizontal space. Sorry I'm being slow but how would I do that? – David Feb 4 '15 at 14:29
• @David Answer updated and this is what can be done at most IMO. You may try to grow the tree to the right (instead of down) if you have some juice left in you ;-) – user11232 Feb 4 '15 at 14:46
• @Ignasi All roads lead to Rome :-). It will again increase the width. – user11232 Feb 4 '15 at 15:01