# tikz trees vertical space and “hanging” branches

I'm trying to create a slide with beamer. Here it is:

\documentclass[t]{beamer} %
\usepackage{tikz} %
\usetikzlibrary{trees} %

\setbeamertemplate{footline}{} %

\begin{document}

\begin{frame}{}
\bigskip
\begin{tikzpicture}[ %
blue/.style={rectangle,draw,fill=blue!20}, %
blue2/.style={rectangle,draw,fill=blue!20,text width=2.9cm,text centered,grow=south}, %
red/.style={rectangle,draw,fill=red!20,text width=2.3cm,text centered}, %
] %
\footnotesize \node [blue] {Here's a basic question for our subject} %
[edge from parent fork down] %
[sibling distance=2cm] %
[sibling distance=0.3cm] %
child {node[red,anchor=south] {Theory A}} %
} %
child {node[red,anchor=south] {Theory B}} %
}} %
[sibling distance=5.5cm] %
[sibling distance=0.8cm] %
child {node[red,anchor=east]{Theory C}} %
child {node[red,anchor=west]{Theory D}} %
} %
\end{tikzpicture}
\end{frame}
\end{document}


The problem is that I also have a "Theory E" and "Theory F" that go under "Answer 4". I would like to increase the vertical space under "Answer 2 leads to another question" and "Answer 3" and "Answer 4"; push "Answer 3" to the left to be under the branch of "Answer 1" to make space for the children of "Answer 4". I can't figure out how to do that.

EDIT: Maybe I should emphasize that I'm specifically looking for a solution that moves "Answer 3" and its children under "Theory A"/"Theory B" so that it lines up vertically with "Answer 1". Then I could have "Answer 4" directly under "Answer 2 leads to another question" and add "Theory E" and "Theory F" as its children. I can't add any horizontal space to the slide (it has fixed dimensions) and I can't make the font any smaller, because I want people to be able to read it (it's already \footnotesize).

with the forest package is simple:

\documentclass[t]{beamer}
\setbeamertemplate{footline}{}

\usepackage[edges]{forest}

\begin{document}

\begin{frame}
\frametitle{solution with the \texttt{forest} package}
\begin{center}
\begin{forest}
for tree={          % style of nodes in the tree
align = center,%   text centered,
fill = red!20, draw,
% style of tree (edges, distances, direction)
grow = south,
forked edge,        % for forked edge
s sep = 2mm,    % sibling distance
l sep = 8mm,    % level distance
fork sep = 4mm,    % distance from parent to branching point
}% end for tree
[Here's a basic question for our subject, fill=blue!20
[Theory A]
]
[Theory B]
]
]
[Theory C]
[Theory D]
]
[Theory E]
[Theory F]
]
]
]
]
\end{forest}
\end{center}
\end{frame}
\end{document}


• used are only elementary function of forest
• that tree can be fit to frame size the used font size is reduced to \small. with this is not need to push branches under node Answer 2 leads to\ another question under left branches. by this the tree is more clear to my opinion)
• minimal nodes size aren't defined, their sizes are left to adoption to their content size
• it is possible to add more sophisticated possibility of forest for coloring nodes regarding to their position in the three. however i estimate that this would make code less clear for start of forest use

addendum: if i correctly understood edit of your question, than you looking for the following tree:

code for this frame is:

\begin{frame}[fragile]
\frametitle{solution with the \texttt{forest} package}
\begin{center}
\begin{forest}
for tree={draw,
fill = red!20,
align = center,
% style of tree (edges, distances, direction)
grow = south,
forked edge,        % for forked edge
s sep = 4mm,    % sibling distance
l sep = 6mm,    % level distance
fork sep = 3mm,    % distance from parent to branching point
}
[Here's a basic question for our subject, fill=blue!20
[Theory A]
[,phantom
[Theory C]
[Theory D]
]
]
[Theory B]
]
]
s sep+=12mm
[,coordinate,name=answ2]
[,coordinate
[Theory E]
[Theory F]
]
]
]
]
]
\draw (answ2) |- ([yshift=2.5mm] answ3.north) -- (answ3);
\end{forest}
\end{center}
\end{frame}

• Thanks for your addition. After playing around with it, I found it was indeed easy to achieve what I wanted. I did not know about the forest package before. – GrB Sep 19 '18 at 15:52
• @GrB, you are welcome!. forest is very powerful package. i still learning it :-) – Zarko Sep 19 '18 at 17:47

You could move the children using [level distance=XXcm] and [sibling distance=XXcm].

\documentclass[t,aspectratio=169]{beamer} %
\usepackage{tikz} %
\usetikzlibrary{trees} %

\setbeamertemplate{footline}{} %

\begin{document}

\begin{frame}{}
\bigskip
\begin{tikzpicture}[ %
blue/.style={rectangle,draw,fill=blue!20}, %
blue2/.style={rectangle,draw,fill=blue!20,text width=2.9cm,text centered,grow=south}, %
red/.style={rectangle,draw,fill=red!20,text width=2.3cm,text centered}, %
] %
\footnotesize \node [blue] {Here's a basic question for our subject} %
[edge from parent fork down] %
[sibling distance=2cm] %
[sibling distance=0.3cm] %
child {node[red,anchor=south] {Theory A}} %
} %
child {node[red,anchor=south] {Theory B}} %
}} %
[sibling distance=8cm] %
[sibling distance=0.8cm] %
child[level distance=2cm]{node[red,anchor=east]{Theory C}} %
child[level distance=2cm]{node[red,anchor=west]{Theory D}} %
} %
\end{tikzpicture}
\end{frame}
\end{document}


Hint: I added [aspectratio=169] to the document class, for a wider screen.

• This will not work for me. It's a beamer slide, so I can't change the aspect ratio (that would mess up the formating of the other slides). That's why I would like to use the space below "Theory A" and "Theory B" for the "Answer 3" branch. I'm constrained by beamer here. The same applies to Zarko's answer below. – GrB Sep 17 '18 at 21:28