我想修剪(用于指示)这棵极小最大树的一些分支。我想在最终树中要修剪的每个分支上画一条交叉线。我似乎无法用合成树以明显的方式打包。有人能建议一种优雅的方式来做到这一点吗?
我想修剪部分叶子的树的一个最小工作示例如下:
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{subfig}
\usepackage[latin1]{inputenc} % Input encoding
\usepackage{amsmath} % Math
\usepackage{empheq}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{synttree}
\begin{document}
\begin{figure}[h]
\centering
\scalebox{0.8}
{
\branchheight{0.4in}
\childsidesep{1em}
\childattachsep{0.1in}
\synttree
[$\nabla$
[$\triangle$
[$\nabla$
[5]
[1]
[4]
]
[$\nabla$
[2]
[7]
[9]
]
[$\nabla$
[3]
[5]
[7]
]
]
[$\triangle$
[$\nabla$
[10]
[2]
[1]
]
[$\nabla$
[5]
[1]
[4]
]
[$\nabla$
[8]
[9]
[2]
]
]
[$\triangle$
[$\nabla$
[3]
[1]
[2]
]
[$\nabla$
[7]
[6]
[5]
]
[$\nabla$
[9]
[8]
[9]
]
]
]
}
\caption{Minimax tree}
\end{figure}
\end{document}
答案1
如果你愿意转向强大的forest
包(语法非常相似),除了包提供的优秀功能外,您还可以使用 TikZ 的全部功能。然后,您可以使用装饰来定义 s 样式,以便轻松应用于所需的边缘;一个小例子:
\documentclass[10pt,a4paper]{article}
\usepackage{forest}
\usetikzlibrary{decorations.markings}
\newsavebox\mybox
\savebox\mybox{%
\tikz{
\draw[ultra thick,red] (-4pt,-4pt) -- (4pt,4pt);
\draw[ultra thick,red] (-4pt,4pt) -- (4pt,-4pt);
}%
}
\tikzset{
myedge/.style={
decoration={
markings,
mark=at position 0.5 with \node {\usebox\mybox};
},
postaction=decorate
}
}
\begin{document}
\begin{figure}[h]
\centering
\scalebox{0.8}
{%
\begin{forest}
[$\nabla$
[$\triangle$,edge={myedge}
[$\nabla$
[5]
[1,edge={myedge}]
[4]
]
[$\nabla$,edge={myedge}
[2]
[7]
[9]
]
[$\nabla$
[3]
[5,edge={myedge}]
[7]
]
]
[$\triangle$
[$\nabla$
[10]
[2,edge={myedge}]
[5]
]
[$\nabla$
[5]
[6]
[4,edge={myedge}]
]
[$\nabla$
[8]
[9]
[2,edge={myedge}]
]
]
[$\triangle$
[$\nabla$
[3]
[7]
[2,edge={myedge}]
]
[$\nabla$,edge={myedge}
[7]
[6]
[5]
]
[$\nabla$,edge={myedge}
[9]
[8]
[9]
]
]
]
\end{forest}
}
\caption{Minimax tree}
\end{figure}
\end{document}
答案2
如果我误解了你的意图,请原谅我,但这就是你想要的东西吗?如果是这样,我只是用了\stackinset
。语法是
\stackinset{H-anchor:l,c,r}{H-offset}{V-anchor:t,c,b}{V-offset}{inset}{base image}
插图可以嵌套,正如我在此处所展示的。这是不得已的方法,因为标签是通过在基础图像上指定物理长度(事后)放置在树上的,而不是使用树编码范围内的逻辑指示符。
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{subfig}
\usepackage[latin1]{inputenc} % Input encoding
\usepackage{amsmath} % Math
\usepackage{empheq}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{synttree}
\usepackage{stackengine}
\def\bigX{\sffamily\bfseries\Huge\textcolor{red}{$\times$}}
\begin{document}
\begin{figure}[h]
\centering
\stackinset{c}{-1.8cm}{c}{0.8cm}{\bigX}{%
\stackinset{c}{-0.5cm}{c}{}{\bigX}{%
\scalebox{0.8}
{
\branchheight{0.4in}
\childsidesep{1em}
\childattachsep{0.1in}
\synttree
[$\nabla$
[$\triangle$
[$\nabla$
[5]
[1]
[4]
]
[$\nabla$
[2]
[7]
[9]
]
[$\nabla$
[3]
[5]
[7]
]
]
[$\triangle$
[$\nabla$
[10]
[2]
[1]
]
[$\nabla$
[5]
[1]
[4]
]
[$\nabla$
[8]
[9]
[2]
]
]
[$\triangle$
[$\nabla$
[3]
[1]
[2]
]
[$\nabla$
[7]
[6]
[5]
]
[$\nabla$
[9]
[8]
[9]
]
]
]
}}}
\caption{Minimax tree}
\end{figure}
\end{document}