1

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

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

\setbeamertemplate{navigation symbols}{} %
\setbeamertemplate{footline}{} %
\setbeamertemplate{headline}{} %

\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] %
    child {node[red,anchor=east] {Answer 1} %
      [sibling distance=0.3cm] %
      child {node[blue2,anchor=east] {Answer 1 may lead to} %
        child {node[red,anchor=south] {Theory A}} %
      } %
      child {node[blue2,anchor=west] {Answer 1 may also lead to} %
        child {node[red,anchor=south] {Theory B}} %
      }} %
    child{node[red,anchor=west] {Answer 2} %
      child {node[blue2,anchor=west] {Answer 2 leads to another question} %
        [sibling distance=5.5cm] %
        child {node[red,anchor=west]{Answer 3} %
          [sibling distance=0.8cm] %
          child {node[red,anchor=east]{Theory C}} %
          child {node[red,anchor=west]{Theory D}} %
        } %
        child {node[red,anchor=east]{Answer 4}}}}; %
  \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.

enter image description here

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).

2

with the forest package is simple:

\documentclass[t]{beamer}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}{}
\setbeamertemplate{headline}{}

\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
         font = \sffamily\scriptsize\linespread{0.8}\selectfont,
        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
    [Answer 1
        [Answer 1\\ may lead to, fill=blue!20
            [Theory A]
        ]
         [Answer 1 may\\ also lead to, fill=blue!20
            [Theory B]
        ]
    ]
    [Answer 2
        [Answer 2 leads to\\ another question, fill=blue!20
            [Answer 3
                [Theory C]
                [Theory D]
            ]
            [Answer 4
                [Theory E]
                [Theory F]
            ]
        ]
    ]
]
  \end{forest}
\end{center}
\end{frame}
\end{document}

enter image description here

  • 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:

enter image description here

code for this frame is:

\begin{frame}[fragile]
\frametitle{solution with the \texttt{forest} package}
\begin{center}
    \begin{forest}
    for tree={draw, 
             font = \sffamily\small\linespread{0.8}\selectfont,
             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
    [Answer 1, 
        [Answer 1\\ may lead to, fill=blue!20
            [Theory A]
            [,phantom
                [Answer 3, no edge,
                 tier=answer, name=answ3
                    [Theory C]
                    [Theory D]
                ]
            ]
            [Theory B]
        ]
     ]
    [Answer 2
        [Answer 2 leads to\\ another question, fill=blue!20,
         s sep+=12mm 
            [,coordinate,name=answ2]
            [,coordinate
                [Answer 4,tier=answer
                    [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
2

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

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

\setbeamertemplate{navigation symbols}{} %
\setbeamertemplate{footline}{} %
\setbeamertemplate{headline}{} %

\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] %
    child {node[red,anchor=east] {Answer 1} %
      [sibling distance=0.3cm] %
      child {node[blue2,anchor=east] {Answer 1 may lead to} %
        child {node[red,anchor=south] {Theory A}} %
      } %
      child {node[blue2,anchor=west] {Answer 1 may also lead to} %
        child {node[red,anchor=south] {Theory B}} %
      }} %
    child{node[red,anchor=west] {Answer 2} %
      child{node[blue2,anchor=west] {Answer 2 leads to another question} %
        [sibling distance=8cm] %
        child[level distance=2cm,sibling distance=8cm]{node[red,anchor=west]{Answer 3} %
          [sibling distance=0.8cm] %
          child[level distance=2cm]{node[red,anchor=east]{Theory C}} %
          child[level distance=2cm]{node[red,anchor=west]{Theory D}} %
        } %
        child[level distance=2cm]{node[red,anchor=east]{Answer 4}}}}; %
  \end{tikzpicture}
\end{frame}
\end{document}

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

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.