我有一棵如下所示的树:
\documentclass[border=2pt,multi,tikz]{standalone}
\usetikzlibrary{trees,arrows}
\begin{document}
\begin{tikzpicture}[edge from parent/.style={draw,-latex}]
\node [draw=none] (q0) {$q_r$}
child {node [draw=none] (q2) {$q_0$}
child {node [draw=none] (q4) {$q_1$}
child {node [draw=none] (q7) {$q_4$}
child {node [draw=none] (q10) {$q_s$}}
}
child {node [draw=none] (q8) {$q_5$}
child {node [draw=none] (q10) {$q_s$}}
}
edge from parent [->] node [left] {$\sigma_1$}
}
child {node [draw=none] (q5) {$q_2$}
child {node [draw=none] (q10) {$q_s$}}
}
child {node [draw=none] (q5) {$q_3$}
child {node [draw=none] (q10) {$q_s$}}
}
};
\node[] at (-0.70,-3) {$\times$};
\node[] at (0.70,-3) {$\times$};
\node[] at (-1.5,-4.45) {$\times$};
\end{tikzpicture}
\end{document}
我需要的是标记所有边缘,并设置所有边缘方向从子节点到父节点。我尝试更改,edge from parent
但edge from child
没有成功。
答案1
- 反转边缘方向使用
edge from parent/.style={draw,latex-}
无关:
- 所有节点的选项
[draw=none]
都是多余的 - 节点
$\times$
可以集成到树中child {node {$\times$} edge from parent[draw=none]}
姆韦:
\documentclass[border=2pt,multi,tikz]{standalone}
\usetikzlibrary{trees,arrows}
\begin{document}
\begin{tikzpicture}[
edge from parent/.style={draw,latex-},
sibling distance = 9mm,
]
\node (q0) {$q_r$}
child {node (q2) {$q_0$}
child {node (q4) {$q_1$}
child {node (q7) {$q_4$}
child {node (q10) {$q_s$} edge from parent node[left]{$\gamma_1$}
} edge from parent node[left]{$\delta_1$}
}
child {node {$\times$} edge from parent[draw=none]}
child {node (q8) {$q_5$}
child {node (q10) {$q_s$} edge from parent node[right]{$\gamma_2$}
} edge from parent node[right]{$\delta_2$}
} edge from parent node[left]{$\sigma_1$}
}
child {node {$\times$} edge from parent[draw=none]}
child {node (q5) {$q_2$}
child {node (q10) {$q_s$} edge from parent node[right]{$\delta_3$}
} edge from parent node[left]{$\sigma_2$}
}
child {node {$\times$} edge from parent[draw=none]}
child { node (q5) {$q_3$}
child {node (q10) {$q_s$} edge from parent node[right]{$\delta_4$}
} edge from parent node[right]{$\sigma_3$}
}
edge from parent node[right] {$\sigma_0$}
};
\end{tikzpicture}
\end{document}
编辑:
用于标记边edge from parent node [<where>] {<label>}
。用于标记父节点和子节点之间的边,应将其放置在子节点之后。参见上文改进的 mwe