平均能量损失

平均能量损失

我想将以下forest决策树的字体大小更改为\footnotesize。当我将 添加font=\footnotesize到 时for tree,只有“名称”的大小会发生变化,但边缘标签(“H”和“T”)不会改变。如果我通过添加 来摆弄decision edge label/.style\footnotesize则会出现错误:

!TeX 容量超出,抱歉 [输入堆栈大小=5000]。
\@setfontsize #1#2#3->\@nomath #1
\ifx \protect \@typeset@protect \let \@curr...
l.53 \end{forest}

平均能量损失

\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}

输出

在此处输入图片描述

答案1

以这种方式设置整棵树的最简单方法是将\footnotesize树放入一个组中。例如:

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

或者,你可以使用以下方法设置font树前导码中每个节点

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

较小的节点

\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}

相关内容