Tikz 中的证明树

Tikz 中的证明树

我想画一棵证明树,它与下面的证明树完全相似 在此处输入图片描述

由于我是 Tikz 的新手,所以我尝试了一下,但得到的却是这个(见下图),这与我想要绘制的内容相差甚远(没有箭头,框不粗体,框的位置......)。

有人能帮助我实现预期的结果吗? 在此处输入图片描述

我的 MWE:

\documentclass{standalone} 
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle,
    draw, align=center,
    top color=white,}]]
  \node {S1|\textbf{R3}}
    child { node {S2|\textbf{R1}} }
       child { node {S3|\textbf{R5}}
        child { node {S5|\textbf{R4}} }
        child { node {S6|\textbf{R6}} } }
    child { node {S4|\textbf{R2}} };

\end{tikzpicture}
\end{document}

答案1

现在我有点时间,这里有一个更好的实现。

\documentclass[border=10pt]{standalone} 
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, arrows.meta}
\begin{document}
\tikzset{
    csw/.style = { % connect from center to south west
        edge from parent path={ 
            (\tikzparentnode) -- (\tikzchildnode.south west)
        },
    },
    cse/.style = {   % connect from center to south east
        edge from parent path={
            (\tikzparentnode) -- (\tikzchildnode.south east)
        },
    },
}

\begin{tikzpicture}[
    sibling distance=5em,
    level 2/.style = {sibling distance=10em},
    -{Stealth[length=5mm, width=2mm]}, grow=up,  % use arrowe, grows the graph up. 
    every node/.style =
        {shape=rectangle split,   % use two-parts rectangular nodes 
        rectangle split parts=2, rectangle split horizontal, 
        draw, thick, align=center, % draw thick lines.
        text width=1.5em},
    every two node part/.style = { % set the style of the second part
        font=\bfseries,            % so we can avoid all the \textbf{}
    }
    ]
    \node{S1 \nodepart{two} R3}
        child [csw] { node {S2 \nodepart{two} R1} }
            child [thick] { node {S3 \nodepart{two} R5 }
                % we need to reset the thickness here, otherwise is inherited    
                child [csw, thin] { node {S5 \nodepart{two} R4} }
                child [cse, thin] { node {S6 \nodepart{two} R6} } 
              }
              child [cse]{ node {S4 \nodepart{two} R2} 
        };
\end{tikzpicture}
\end{document}

结果是

精炼结果

原始答案

\documentclass{standalone} 
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,
    ->, >=stealth, grow=up,  % use arrowe, grows the graph up. 
    every node/.style = {shape=rectangle split,   % use two-parts rectangular nodes 
        rectangle split parts=2, rectangle split horizontal, 
        draw, thick, align=center, % draw thick lines.
    top color=white,}]
    \node  {S1 \nodepart{two}\textbf{R3}}
        child { node {S2 \nodepart{two}\textbf{R1}} }
        child { node {S3 \nodepart{two}\textbf{R5}}
                child { node {S5 \nodepart{two}\textbf{R4}} }
                child { node {S6 \nodepart{two}\textbf{R6}} } }
                child { node {S4 \nodepart{two}\textbf{R2}} };
\end{tikzpicture}
\end{document}

输出

应该将其更改为将箭头发送到edge from parent path手册中的选项,并使两个部分大小相同(查看同一手册中的形状库,具有多部分的形状)。

相关内容