使用 Forest /Tikzpicture 的代码树

使用 Forest /Tikzpicture 的代码树

我想画一棵那样的代码树。在此处输入图片描述

我对 Latex 还比较陌生,目前我在这里遇到了困难。有人能帮助我继续吗?问候

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{backgrounds,fit}
\begin{document}
\begin{forest} 
for tree={draw, circle, l sep+=0.1em, inner sep=0.01em}
[,fill
    [{$.$}, edge label={node[midway,left]{$11$}}
        [$.$, edge label={node[midway,left]{$01$}}
            [$.$, edge label={node[midway,left]{$10$}}
                [$.$, edge label={node[midway,left]{$10$}}]
                [$.$, edge label={node[midway,right]{$0.18$}}]
            ]
            [$.$, edge label={node[midway,right]{$01$}}
                [$.$, edge label={node[midway,left]{$0$}}]
                [$.$, edge label={node[midway,right]{$09$}}]
            ]
        ]
        [$.$, edge label={node[midway,right]{$50$}}
            [$.$, edge label={node[midway,left]{$00$}}
                [$.$, edge label={node[midway,left]{$00$}}]
                [$.$, edge label={node[midway,right]{$00$}}]
            ]
            [$.$, edge label={node[midway,right]{$00$}}
                [$.$, edge label={node[midway,left]{$0$}}]
                [$.$, edge label={node[midway,right]{$5$}}]
            ]
        ]
    ]
    [{$.$}, edge label={node[midway,right]{$00$}}
        [$.$, edge label={node[midway,left]{$00$}}
            [$.$, edge label={node[midway,left]{$6$}}
                [$.$, edge label={node[midway,left]{$7$}}]
                [$.$, edge label={node[midway,right]{$8$}}]
            ]
            [$.$, edge label={node[midway,right]{$9$}}
                [$.$, edge label={node[midway,left]{$05$}}]
                [$.$, edge label={node[midway,right]{$07$}}]
            ]
        ]
        [$.$, edge label={node[midway,right]{$00$}}
            [$.$, edge label={node[midway,left]{$00$}}
                [$.$, edge label={node[midway,left]{$5$}}]
                [$.$, edge label={node[midway,right]{$7$}}]
            ]
            [$.$, edge label={node[midway,right]{$10$}}
                [$.$, edge label={node[midway,left]{$01$}}]
                [$.$, edge label={node[midway,right]{$00$}}]
            ]
        ]
    ]
]
\end{forest}
\end{document}

答案1

我不明白目标图片中的数字模式,也不明白代码中的数字如何与该目标相对应。出于这些原因,我保留了标签的内容,只改变了树的外观。

这棵树是gray。树中突出显示的路径是darkgray一条thick线。

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
  for tree={
    draw=gray,
    circle,
    fill=gray,
    s sep'+=5pt,
    inner sep=.75pt,
  },
  label me/.style={
    edge label={node [midway,inner sep=1pt,above,sloped,font=\footnotesize] {$#1$}},
  },
  tikz+={
    \draw [-Latex, gray] (.north west) ++(-15pt,15pt) -- ++(-25pt,0) node [midway, above, anchor=west, font=\footnotesize, inner sep=1pt, rotate=90] {1};
    \draw [-Latex, gray] (.north east) ++(15pt,15pt) -- ++(25pt,0) node [midway, above, anchor=east, font=\footnotesize, inner sep=1pt, rotate=-90] {0};
  },
  [
    [, label me=11
        [, label me=01
            [, label me=10
                [, label me=10]
                [, label me=0.18]
            ]
            [, label me=01
                [, label me=0]
                [, label me=09]
            ]
        ]
        [, label me=50
            [, label me=00
            [, label me=00, before typesetting nodes={for current and ancestors={fill=darkgray, draw=darkgray, edge+={darkgray, thick} } }]
                [, label me=00]
            ]
            [, label me=00
                [, label me=0]
                [, label me=5]
            ]
        ]
    ]
    [, label me=00
        [, label me=00
            [, label me=6
                [, label me=7]
                [, label me=8]
            ]
            [, label me=9
                [, label me=05]
                [, label me=07]
            ]
        ]
        [, label me=00
            [, label me=00
                [, label me=5]
                [, label me=7]
            ]
            [, label me=10
                [, label me=01]
                [, label me=00]
            ]
        ]
    ]
  ]
\end{forest}
\end{document}

重新格式化的树

相关内容