5

I want to change the font size of the following forest decision tree to \footnotesize. When I add font=\footnotesize to for tree, it only the size of the "Name"s get changed, but not the edge labels ("H" and "T"). If I fiddle with the decision edge label/.style by adding \footnotesize in it, an error would occur:

! TeX capacity exceeded, sorry [input stack size=5000].
\@setfontsize #1#2#3->\@nomath #1
\ifx \protect \@typeset@protect \let \@curr...
l.53 \end{forest}

MWE

\documentclass{article}
\usepackage{mathtools,forest}
\def\getfirst#1;#2\endget{#1}
\def\getsecond#1;#2\endget{#2}
\forestset{declare toks={elo}{}} % edge label options
\begin{document}
\color{red}
\begin{forest}
  anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
  for tree={font=\footnotesize,
    s sep=5mm,l=15mm,
    if n children=0{anchors=north}{
    if n=1{anchors=south east}{anchors=south west}},
    content format={$\forestoption{content}$}
  },
  anchors=south, outer sep=2pt,
  nomath/.style={content format=\forestoption{content}},
  dot/.style={tikz+={\draw[#1](.child anchor)circle[radius=2pt];}},
  dot={fill={white}},for descendants={dot={fill}}, % initial node hollow, rest solid
  decision edge label/.style n args=3{
    edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$#3$}}
  },
  decision/.style={if n=1
    {decision edge label={left}{east}{#1}}
    {decision edge label={right}{west}{#1}}
  },
  delay={for descendants={
    decision/.expanded/.wrap pgfmath arg={\getsecond#1\endget}{content},
    content/.expanded/.wrap pgfmath arg={\getfirst#1\endget}{content},
  }},
  [Name,nomath
    [Name;{+\epsilon},nomath
      [;{H}
        [;{H}]
        [;{T}]
      ]
      [;{T}
        [;{H}]
        [;{T}]
      ]
    ]
    [Name;{-\epsilon},nomath
      [;{H}
        [;{H}]
        [;{T}]
      ]
      [;{T}
        [;{H}]
        [;{T}]
      ]
    ]
  ]
\end{forest}
\end{document}

Output

enter image description here

  • Easiest: {\footnotesize\begin{forest}...\end{forest}}. – cfr Nov 14 '15 at 2:27
7

The easiest way to set the entire tree this way is to simply put \footnotesize in a group with the tree. For example:

{\footnotesize
  \begin{forest}
    ...
  \end{forest}%
}

Alternatively, you can set the font for every node in the tree's preamble using

 /tikz/every node/.append style={font=\footnotesize},

smaller nodes

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{mathtools,forest}
\def\getfirst#1;#2\endget{#1}
\def\getsecond#1;#2\endget{#2}
\forestset{declare toks={elo}{}} % edge label options
\begin{document}
\color{red}
\begin{forest}
  anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
  /tikz/every node/.append style={font=\footnotesize},
  for tree={
    font=\footnotesize,
    s sep=5mm,l=15mm,
    if n children=0{anchors=north}{
    if n=1{anchors=south east}{anchors=south west}},
    content format={$\forestoption{content}$},
  },
  anchors=south, outer sep=2pt,
  nomath/.style={content format=\forestoption{content}},
  dot/.style={tikz+={\draw[#1](.child anchor)circle[radius=2pt];}},
  dot={fill={white}},for descendants={dot={fill}}, % initial node hollow, rest solid
  decision edge label/.style n args=3{
    edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$#3$}}
  },
  decision/.style={if n=1
    {decision edge label={left}{east}{#1}}
    {decision edge label={right}{west}{#1}}
  },
  delay={for descendants={
    decision/.expanded/.wrap pgfmath arg={\getsecond#1\endget}{content},
    content/.expanded/.wrap pgfmath arg={\getfirst#1\endget}{content},
  }},
  [Name,nomath
    [Name;{+\epsilon},nomath
      [;{H}
        [;{H}]
        [;{T}]
      ]
      [;{T}
        [;{H}]
        [;{T}]
      ]
    ]
    [Name;{-\epsilon},nomath
      [;{H}
        [;{H}]
        [;{T}]
      ]
      [;{T}
        [;{H}]
        [;{T}]
      ]
    ]
  ]
\end{forest}
\end{document}
  • How would you change only font size of labels of the edges while leaving the nodes of the tree unchanged? – Fibo Kowalsky May 10 '16 at 2:29
  • @FiboKowalsky Just edit edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}] ... to add the relevant font change. – cfr May 10 '16 at 2:45
  • 1
    @FiboKowalsky For example, edge label/.expanded={node[midway,auto=#1,anchor=#2,font=\scriptsize,\forestoption{elo}] ... would make them all \scriptsize. – cfr May 10 '16 at 23:38
  • What initially I meant was solution in this fashion (the example dosen't work): /tikz/every edge label/.append style={font=\Large}, – Fibo Kowalsky May 12 '16 at 1:35
  • @FiboKowalsky Which example doesn't work? Why don't you ask a new question since your question is not the one I answered here and it is hard to answer another question in comments. – cfr May 12 '16 at 1:42

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.