![使用 Tikz 为树上色](https://linux22.com/image/362802/%E4%BD%BF%E7%94%A8%20Tikz%20%E4%B8%BA%E6%A0%91%E4%B8%8A%E8%89%B2.png)
我想突出显示使用 tikz 和 forest 绘制的概率树上的某条路径(感谢此来源):
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{forest,nicefrac}
\begin{document}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right, sloped]
\node[bag] {}
child {
node[bag] {II $(2R,1B)$}
child {
node[end, label=right:
{$P(B\cap II)=\frac{1}{2}\cdot\frac{1}{3}$}] {}
edge from parent
node[above] {$B$}
node[below] {$\frac{1}{3}$}
}
child {
node[end, label=right:
{$P(R\cap II)=\frac{1}{2}\cdot\frac{2}{3}$}] {}
edge from parent
node[above] {$R$}
node[below] {$\frac{2}{3}$}
}
edge from parent
node[above] {$II$}
node[below] {$\frac{1}{2}$}
}
child {
node[bag] {I $(2R,4B)$}
child {
node[end, label=right:
{$P(B\cap I)=\frac{1}{2}\cdot\frac{4}{6}$}] {}
edge from parent
node[above] {$B$}
node[below] {$\frac{4}{6}$}
}
child {
node[end, label=right:
{$P(R\cap I)=\frac{1}{2}\cdot\frac{2}{6}$}] {}
edge from parent
node[above] {$R$}
node[below] {$\frac{2}{6}$}
}
edge from parent
node[above] {$I$}
node[below] {$\frac{1}{2}$}
};
\end{tikzpicture}
\end{document}
我如何突出显示路径 I、R?只需使边缘标记或使用其他颜色或更改背景颜色即可突出显示,无论您认为哪种做法更好。