# Control tree diagram branches

I have the following tree:

\begin{center}
\begin{forest}
[Tests
[Case 1
[\text{OGL1}]
[\text{OGL2}]
[\text{OGL3}]
[\text{OGL4}]
]
[Case 2
[\text{OGL1}]
[\text{OGL2}]
[\text{OGL3}]
[\text{OGL4}]
]
[Case 3
[\text{OGL1}]
[\text{OGL2}]
[\text{OGL3}]
[\text{OGL4}]
]
[Case 4
[\text{OGL1}]
[\text{OGL2}]
[\text{OGL3}]
[\text{OGL4}]
]
]
\end{forest}
\end{center}


However, the tree is too wide and goes out of the paper.

Is there a nice way to make it fit in the paper without having letters on each other?

If there a different type of tree that can solve it, it also will be nice to know.

Thank you!

• It may work better as a horizontal (rather than vertical) forest tree. – Aubrey Blumsohn Mar 24 '18 at 15:40
• One reason you may have got an answer which doesn't fit the tree into your page area is that you did not provide a complete minimal example, so we have no way of knowing the size of your text block. The answer you currently have assumes you are using A4 paper with 12pt font (but the layout is still configured for US letter), with default margins. But if you are using anything else, all bets are off. – cfr Mar 26 '18 at 23:06
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Jun 30 '18 at 14:02

Like so?

No idea what your \text is for so eliminated those

\documentclass[a4paper,12pt]{article}

\usepackage{forest}

\begin{document}

\begin{forest}
for tree={
child anchor=west,
parent anchor=east,
grow'=east,
%minimum size=1cm,%new possibility
text width=4cm,%
draw,
anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
(.child anchor) -| +(-5pt,0) -- +(-5pt,0) |-
(!u.parent anchor)\forestoption{edge label};
},
}
[Tests
[Case 1
[{OGL1}]
[{OGL2}]
[{OGL3}]
[{OGL4}]
]
[Case 2
[{OGL1}]
[{OGL2}]
[{OGL3}]
[{OGL4}]
]
[Case 3
[{OGL1}]
[{OGL2}]
[{OGL3}]
[{OGL4}]
]
[Case 4
[{OGL1}]
[{OGL2}]
[{OGL3}]
[{OGL4}]
]
]
\end{forest}

\end{document}


• ye it looks nice however if there an option to make it to the width of the paper I prefer. – Ben Mar 24 '18 at 16:11
• You mean you randomly want to change the length of the lines or the width of the boxes, the text and fonts or what? – Aubrey Blumsohn Mar 24 '18 at 17:14
• As you can see, case 4 is outside of the paper. I would like to make for example Case 1 and Case 3 in let say upper floor and Case 2 and Case 4 in lower floor so it can be less wide and yet all connected directly to "Tests". – Ben Mar 24 '18 at 21:37
• @Ben not really sure what this means. – Aubrey Blumsohn Mar 25 '18 at 9:09

It is hard to offer advice about how to fit something into a box without knowing the size of the box, but this is essentially what you've asked people to do. That is, because your example isn't complete, we can only guess your choice of font, default font size, paper size, margins and so on. A better answer would require more complete information.

In what follows, I assume that you are using the article class with default settings. This means US letter paper (216 x 279 mm) in portrait orientation with 10pt Computer Modern serif, sans and typewriter, and default margins, skips and so on.

I suggest setting the tree out 'directory-style'. Depending on the potential width of the nodes' contents, you might either typeset the whole tree this way or switch to this style at an appropriate point.

If the nodes' contents may actually be significantly wider, you might set it like this:

showframe is used to mark the text block, margins etc. Obviously, you shouldn't load this in your real document, but the lines are useful here.

If the nodes' contents is really short, as in the example, I think it looks better to switch after the first children:

Here forked edge is used to get a similar style for the edges between the root and its children.

As of Forest 2, these styles are simple to implement using the edges library, as the following code illustrates.

\documentclass{article}
\usepackage[edges]{forest}
\usepackage{showframe}
\begin{document}

\begin{forest}
for tree={folder, grow'=0}
[Tests
[Case 1
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 2
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 3
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 4
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
]
\end{forest}

\begin{forest}
where level>=1{if level=1{forked edge}{}, folder, grow'=0}{}
[Tests
[Case 1
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 2
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 3
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
[Case 4
[OGL1]
[OGL2]
[OGL3]
[OGL4]
]
]
\end{forest}

\end{document}

• The fork style looks very nice however im getting a clash with fancyhdr package. – Ben Apr 3 '18 at 18:03
• @Ben That is not the problem. Of that I'm certain. I use Forest all the time with fancyhdr: there is no incompatibility here. However, without a minimal example, I can't say what the problem is. – cfr Apr 4 '18 at 2:14