Tikz 森林前的额外节点

Tikz 森林前的额外节点

我想将森林与第一个节点上的某种变量启动结合起来。

这是我目前拥有的代码

\documentclass[]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\forestset{
    default preamble={
        before typesetting nodes={
            !r.replace by={[, coordinate, append]}
        },
        where n children=0{
            tier=word,
        }{
            where n children=0{
            }{
                diamond, aspect=3,
            }
        },
        where level=1{}{
            if n=1{
                edge label={node[pos=.2, above] {yes}},
            }{
                edge label={node[pos=.2, above] {no}},
            }
        },
        for tree={ 
            edge+={thick, -Latex},%math content,
            s sep'+=0.3cm,
            %draw,
            thick,
            edge path'={ (!u) -| (.parent)},
        }
    }
}

\begin{document}
    
        \begin{forest} 
            [{$a_i=a_{i-1}, (a_0=1)$}\\{$b_i=b_{i-1}, (b_0=1)$}, align=center, base=bottom
            [{$a_i=1$},draw
            [nothing,draw]
            [{$t_i>3$},draw
            [{$l_i > 10$},draw
            [{$x_i \in A$},draw % und zwischen 3 und 50 Zeichen
            [nothing,draw] 
            [{$z = 1$},draw
            [nothing,draw]
            [I am Lorde yayaya,draw]   
            ]
            ]
            [nothing,draw] 
            ]
            [{$Speeder_i=1$},draw]   
            ]
            ]
            ]
        \end{forest}
    
\end{document}

它看起来像这样 在此处输入图片描述

但它应该看起来像这样 在此处输入图片描述

答案1

鞋面no来自你的第一个选择

before typesetting nodes={% I don't even know what that does …
  !r.replace by={[, coordinate, append]}
},

只要删除它就可以删除no。(我不知道它是干什么的……)

a_i您现在最上面的节点(带有和方程的节点b_i)有两个问题:

  1. 它使用diamond形状。

    我们用

    where n children<=1{}{diamond, aspect=3}
    

    而不是 n children=0,因为我们只想要diamond当节点有 2 个或更多子节点时的形状。(我想where n children >=2{diamond, aspect=3}{}也应该可行。)

  2. -|它通过您通过 设置的路径连接到其子节点edge path'-|路径操作对于垂直且太宽的节点不太适用。这个节点甚至是垂直的。

    我们将使用

    where level> = 2{
      edge path'={ (!u) -| (.parent)}
    }{}
    

代码

我用 标记了更改的行%%%!

\documentclass[]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\forestset{
  default preamble={
%    before typesetting nodes={%%%! I don't even know what that does …
%      !r.replace by={[, coordinate, append]}
%    },
    where n children=0{
      tier=word,
    }{
      where n children< = 1{%%%! changed from where n children=0
      }{
          diamond, aspect=3,
      }
    },
    where level=1{}{
      if n=1{
          edge label={node[pos=.2, above] {yes}},
      }{
          edge label={node[pos=.2, above] {no}},
      }
    },
    for tree={ 
      edge+={thick, -Latex},%math content,
      s sep'+=0.3cm,
      %draw,
      thick,
      where level> = 2{%%%! added condition for edge path'
        edge path'={ (!u) -| (.parent)}
      }{},
    }
  }
}

\begin{document}
\begin{forest}
[{$a_i=a_{i-1}, (a_0=1)$}\\{$b_i=b_{i-1}, (b_0=1)$},
  align=center,
  yshift=1cm %%%! base=bottom removed (only one node on this level)
             %%%! and yshift=1cm added (to make the arrow longer)
  [{$a_i=1$}, draw
    [nothing, draw]
    [{$t_i>3$}, draw
      [{$l_i > 10$}, draw
        [{$x_i \in A$}, draw % und zwischen 3 und 50 Zeichen
          [nothing, draw]
          [{$z = 1$}, draw
            [nothing, draw]
            [I am Lorde yayaya, draw]
          ]
        ]
        [nothing, draw] 
      ]
      [{$Speeder_i=1$}, draw]
    ]
  ]
]
\end{forest}
\end{document}

输出

在此处输入图片描述

相关内容