我正在尝试创建如下状态树。
我的实际问题是我不知道如何添加放置在树左侧的数字(如图所示)。
数字放置在箭头的级别,而不是与节点的级别。
此外,您能告诉我如何使标记的箭头更粗吗?
这是我编写的代码片段:
\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\begin{document}
\begin{tikzpicture}[nodes={draw, circle}, ->,accepting/.style={double distance=2pt, outer sep=0.75pt+\pgflinewidth}]
\node{$q_0$}
child { node {$q_0$}
child { node {$q_0$}
child { node {$q_0$}
child{node {$q_0$}}
}
child { node {$q_1$}
child{node [accepting]{$q_2$}}
}
}
}
child [missing]
child { node {$q_1$}
child { node {$q_2$} }
};
\end{tikzpicture}
\end{document}
答案1
使用森林很简单:
\documentclass[12pt]{article}
\usepackage{forest}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
quotes}
\begin{document}
\begin{forest}
for tree = {
circle,
draw,
math content,
edge = {draw, semithick, -{Straight Barb[scale=0.8]}},
/tikz/E/.style = {draw=red, very thick, -{Straight Barb[scale=0.8]}},
l sep=7mm,
s sep=12mm
}
[q_0, name=n0
[q_0, name=n1, edge=E
[q_0, name=n2, edge=E
[q_0, name=n3
[q_0, name=n4]
]
[q_1, edge=E
[q_2, double, edge=E]
]
]
]
[,phantom]
[q_1
[q_2]
]
]
\tikzset{
L/.style = {auto, font=\large\sffamily\bfseries},
}
\coordinate[left=of n4] (aux);
\path (aux) to[L, "1"] (aux |- n3)
to[L, "0"] (aux |- n2)
to[L, "1"] (aux |- n1)
to[L, "0"] (aux |- n0);
\end{forest}
\end{document}