2

I'm new to LaTeX and need to make a beamer presentation in which I want to show a tree like the one below. As I have limited time I used forest for this because it seemed the easiest and fastest way for me to do this.

Now I want numbers to be below the external nodes. Optimal solution would be small numbers below and outside the node itself but for now I would be glad for small numbers inside the node and smaller distance between real node entry and selfmade "label" in new line.

I've tried label as well as pin option in node but it's not below like I wanted it. Can anyone please help me? This is like I try to make it look like: tree with label below nodes

This is what I already achieved:

\documentclass[aspectratio=169,xcolor=dvipsnames]{beamer}
\usepackage[edges]{forest}
\begin{document}

    \begin{forest}
                for tree={circle, draw, 
                 minimum size=1.5em,
                    inner sep=1pt, 
                   align=center, top color=white},
                for leaves={rectangle}     
            [, top color=gray, bottom color=gray, minimum size=4mm
             [E
               [ILIG, pin={\tiny 3}]
               [U
                 [CH,label=1]
                 [LE\\ \scriptsize 5]]]
             [FLOG \\ \scriptsize 2]
             [GEL
                 [BE\\ \scriptsize 7]
                 [D\\ \scriptsize 8]]
             [MIT\\ \scriptsize 4]
             [ZU\\ \scriptsize 6]]
    \end{forest}
    
\end{document}

What it looks like

After using the suggested solution I recieved the following error in frame environment: ! Illegal parameter number in definition of \[email protected] \end{frame} Fixed error by adding [fragile] after frame, so this is working code:

\documentclass[aspectratio=169,xcolor=dvipsnames]{beamer}
\usepackage[edges]{forest}

\begin{document}
\begin{frame}[fragile]

\begin{forest}
  for tree={circle, draw, 
    minimum size=1.5em,
    inner sep=1pt, 
    align=center, top color=white
  },
  for leaves={rectangle},
  my label/.style={label={[font=\scriptsize]south:#1}},
  [, top color=gray, bottom color=gray, minimum size=4mm
    [E
      [ILIG, my label=3]
      [U
        [CH, my label=1]
        [LE, my label=5]]]
    [FLOG, my label=2]
    [GEL
      [BE, my label=7]
      [D, my label=8]]
    [MIT, my label=4]
    [ZU, my label=6]]
\end{forest}
\end{frame}
\end{document}

1 Answer 1

2

label is the right way to go, but to achieve the desired result, labels need to be placed to the south of the main nodes: label={south:label text}. And the best way to change the font size in the label is using label options: label={[font=\scriptsize]south:label text}. More information on key label can be found in the PGF/TikZ manual, section 17.10.

Below, my label style, setting the placement and font size of a label, is defined for convenient usage in the tree.

\documentclass[aspectratio=169,xcolor=dvipsnames]{beamer}
\usepackage[edges]{forest}
\begin{document}

\begin{forest}
  for tree={circle, draw, 
    minimum size=1.5em,
    inner sep=1pt, 
    align=center, top color=white
  },
  for leaves={rectangle},
  my label/.style={label={[font=\scriptsize]south:#1}},
  [, top color=gray, bottom color=gray, minimum size=4mm
    [E
      [ILIG, my label=3]
      [U
        [CH, my label=1]
        [LE, my label=5]]]
    [FLOG, my label=2]
    [GEL
      [BE, my label=7]
      [D, my label=8]]
    [MIT, my label=4]
    [ZU, my label=6]]
\end{forest}
4
  • Thanks a lot for your help!! This works fine as long as I just use it inside \begin{document} ... \end{document}. If I just put it inside \begin{frame} it no longer works and doesn't compile with this error message: ! Illegal parameter number in definition of \iterate.<to be read again>1 \end{frame} Am I doing something wrong?
    – Michelle
    Commented Jan 7, 2023 at 15:40
  • I believe this is due to how Beamer collects the frame environment. Doubling the hashes should do the trick: my label/.style={label={[font=\scriptsize]south:##1}}, Commented Jan 8, 2023 at 16:25
  • Unfortunately the following error stitll occurs: ! Illegal parameter number in definition of \beamer@doifinframe.<to be read again>1 \end{frame}. I've added the code I used in my question
    – Michelle
    Commented Jan 8, 2023 at 19:45
  • 2
    @Michelle Try using \begin{frame}[fragile] instead. This should work.
    – Alan Munn
    Commented Jan 8, 2023 at 20:02

You must log in to answer this question.

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