是否可以在 Beamer 中绘制解析证明树

是否可以在 Beamer 中绘制解析证明树

如何绘制解析树,例如这里的例子

在此处输入图片描述

答案1

这棵树可以很容易地使用TikZ

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit,trees}

\begin{document}

\begin{tikzpicture}[
  grow'=up,
  level 1/.style={sibling distance=14em},
  level 2/.style={sibling distance=6em}]
\node (f) {False} 
child { node (1l) {$p(a)$}
  child {node (2ll) {$\neg p(a)$}}
  child {node (2lr) {$p(a)\vee p(b)$}}
}
child {node (1r) {$\neg p(a)$}
child {node (2rl) {$p(X)\vee r(X)$}}
child {node (2rr) {$\neg r(b)$}}
};
\end{tikzpicture}

\end{document}

在此处输入图片描述

唯一可能不那么简单的是绘制一些公式组周围的闭合路径;这里的一种可能的方法是使用Jake's answer凸包的填充边界

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit,trees}

\newcommand{\convexpath}[2]{
[   
    create hullnodes/.code={
        \global\edef\namelist{#1}
        \foreach [count=\counter] \nodename in \namelist {
            \global\edef\numberofnodes{\counter}
            \node at (\nodename) [draw=none,name=hullnode\counter] {};
        }
        \node at (hullnode\numberofnodes) [name=hullnode0,draw=none] {};
        \pgfmathtruncatemacro\lastnumber{\numberofnodes+1}
        \node at (hullnode1) [name=hullnode\lastnumber,draw=none] {};
    },
    create hullnodes
]
($(hullnode1)!#2!-90:(hullnode0)$)
\foreach [
    evaluate=\currentnode as \previousnode using \currentnode-1,
    evaluate=\currentnode as \nextnode using \currentnode+1
    ] \currentnode in {1,...,\numberofnodes} {
-- ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode)$)
  let \p1 = ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode) - (hullnode\currentnode)$),
    \n1 = {atan2(\x1,\y1)},
    \p2 = ($(hullnode\currentnode)!#2!90:(hullnode\nextnode) - (hullnode\currentnode)$),
    \n2 = {atan2(\x2,\y2)},
    \n{delta} = {-Mod(\n1-\n2,360)}
  in 
    {arc [start angle=\n1, delta angle=\n{delta}, radius=#2]}
}
-- cycle
}

\begin{document}

\begin{tikzpicture}[
  grow'=up,
  level 1/.style={sibling distance=14em},
  level 2/.style={sibling distance=6em}]
\node (f) {False} 
child { node (1l) {$p(a)$}
  child {node (2ll) {$\neg p(a)$}}
  child {node (2lr) {$p(a)\vee p(b)$}}
}
child {node (1r) {$\neg p(a)$}
child {node (2rl) {$p(X)\vee r(X)$}}
child {node (2rr) {$\neg r(b)$}}
};
\draw[cyan!70!black] \convexpath{f,1l.west,1r.east}{13pt};
\draw[red!70!black] \convexpath{1r,2rl.west,2rr.east}{12pt};
\end{tikzpicture}

\end{document}

在此处输入图片描述

您可以访问与以下内容相关的许多资源TikZ

相关内容