2

I have a slide with some text and I want to add a tree under them.

something like the gif below. enter image description here

The pause for each node is really not important but if possible, it will be much better. and is there possible to change forest size?

I tried this code but tree exceed the page size:

\documentclass{beamer}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\usepackage{lipsum}

\begin{document}
\begin{frame}[fragile]{Introduction}
    \begin{itemize}
        \setlength\itemsep{1em}
        \item \lipsum[1][1-5]
        \item \lipsum[1][1-5]
    \end{itemize}
    \begin{figure}
        \begin{forest}
            for tree = {
                circle, 
                draw, 
                edge = {-Straight Barb, semithick},
                l sep=8mm, 
                s sep=15mm, 
                minimum size = 3em,
                EL/.style 2 args = {edge label={%
                        node[midway, font=\footnotesize, align=center,
                        inner sep=2pt, anchor=south #1]{#2}},
                },
            }
            [Outlook,
            [Humidity, EL={east}{sunny}
            [Play, EL={east}{H $\leq$ 75}]
            [Don't play, EL={west}{H > 75}]
            ]
            [Play, EL={east}{Overcast}]
            [Wind, EL={west}{Raining}
            [Play, EL={east}{weak}]
            [Don't play, EL={west}{strong}]
            ]
            ]
        \end{forest}
    \end{figure}
\end{frame}
\end{document}
10
  • 1
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Dec 3, 2023 at 11:20
  • 1
    Have a look at the overlay-beamer-styles tikz library to uncover nodes step-by-step Dec 3, 2023 at 11:21
  • Can you clarify what problem you face in adding the tree? From your previous question tex.stackexchange.com/q/702890/36296 it seems like you know how to draw basic trees. What exactly is missing to reproduce the one shown in your image? Dec 3, 2023 at 14:01
  • I'd suggest this question as base concept, except for the time constraint.
    – FHZ
    Dec 3, 2023 at 14:05
  • 2
    But don't put your tree in a scalebox as the top ranking answer to the earlier question does. The lower ranked answer is much better. Alternatively, look at options for tikz scaling.
    – cfr
    Dec 3, 2023 at 23:28

1 Answer 1

7
\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{overlay-beamer-styles}
\usepackage{lipsum}

\forestset{
  visible on/.style={
    for tree={
      /tikz/visible on={#1},
      edge+={/tikz/visible on={#1}}}}}

\begin{document}
\begin{frame}[fragile]
    \frametitle{Introduction}
    \begin{itemize}
        \setlength\itemsep{1em}
        \item \lipsum[1][1-5]
        \item \lipsum[1][1-5]
    \end{itemize}
    \begin{figure}
        \scriptsize
        \begin{forest}
            for tree = {
                ellipse, 
                draw, 
                edge = {-Straight Barb, semithick},
                l sep=1.5em, 
                s sep=2.5em, 
                minimum width=6em,
                EL/.style 2 args = {edge label={%
                        node[midway, font=\tiny, align=center,
                        inner sep=2pt, anchor=south #1]{#2}},
                },
            }
            [Outlook
            [Humidity, visible on=<2->, EL={east}{sunny}
            [Play, visible on=<3->, visible on=<3->, EL={east}{H $\leq$ 75}]
            [Don't play, visible on=<4->, EL={west}{H > 75}]
            ]
            [Play, visible on=<5->, EL={east}{Overcast}]
            [Wind, visible on=<6->, EL={west}{Raining}
            [Play, visible on=<7->, EL={east}{weak}]
            [Don't play, visible on=<8->, EL={west}{strong}]
            ]
            ]
        \end{forest}
    \end{figure}
\end{frame}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .