使用“地面”符号表示二叉树中的空子节点

使用“地面”符号表示二叉树中的空子节点

我使用ground符号来表示二叉树中的空子节点。但是地面符号中有箭头。我该如何移除它们?

\documentclass{llncs}
\usepackage{llncsdoc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning,pgfplots.groupplots}
\usepackage{circuitikz}

\begin{document}
\tikzset
{
        treenode/.style = {circle, draw=black, align=center, minimum size=1cm},
        subtree/.style  = {isosceles triangle, draw=black, align=center, minimum height=0.5cm, minimum width=1cm, shape border rotate=90, anchor=north}
}
\begin{figure}[t]
\centering
\caption{A binary tree. \label{fig:simple}}
{
    \begin{tikzpicture}[->,scale=0.6, transform shape]
        %-----------------------------------------------------------------------
        \node (x)[treenode]                                 at (-3,0)       {$X$ \\ 100};
        \node (y)[treenode, fill=black!20]  at (-4.5,-1.5)  {$Y$ \\ 50};
        \node (a)[subtree]                                  at (-1,-1)      {\Large $\alpha$};
        \node (b)[subtree]                                  at (-6,-2.5)    {\Large $\beta$};
        \node (gnd)[ground]                                 at (-2.5,-2.5)  {}; 

        \path[every node/.style={font=\sffamily\small}]
        (-3, 1) edge node                   {} (x)
        (x)         edge node                   {} (y)
        (x)         edge node                   {} (a.north)
        (y)         edge node                   {}(b.north)
        (y)         edge node                   {}(gnd);
        %-----------------------------------------------------------------------
    \end{tikzpicture}
}
\end{figure}
\end{document}

输出

答案1

我想在这里提出一种替代方案,使用库ground中的符号circuits.ee.IEC并使用强大的forest绘制树的包:

在此处输入图片描述

代码:

\documentclass{llncs}
\usepackage{llncsdoc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning,pgfplots.groupplots,circuits.ee.IEC}
\usepackage{forest}

\tikzset{
  treenode/.style = {
    circle, 
    draw=black, 
    align=center, 
    minimum size=1cm
  },
  subtree/.style  = {
    isosceles triangle, 
    draw=black, 
    align=center, 
    minimum height=0.5cm,   
    minimum width=1cm, 
    shape border rotate=90, 
    anchor=north
  }
}

\newsavebox\mybox
\newcommand\Ground{%
  \begin{tikzpicture}[circuit ee IEC,scale=1.5]
  \draw (0,0) to +(0,-1.35ex) node[ground,rotate=-90,inner sep=0pt,xshift=0.65ex] {};
  \end{tikzpicture}%
}
\savebox\mybox{$\Ground$}

\begin{document}

\begin{figure}[t]
\centering
\caption{A binary tree. \label{fig:simple}}
\begin{forest}
for tree={
  scale=0.6,
  parent anchor=south,
  child anchor=north,
  edge={->},
  s sep=20pt,
}
[
  [$X$\\$100$,treenode
    [$Y$\\$50$,treenode,fill=gray!30
      [$\beta$,subtree]
      [\usebox\mybox,yshift=0.5cm]
    ]
    [$\alpha$,subtree
    ]
  ]
]
\end{forest}
\end{figure}

\end{document}

答案2

经过一小时的调查,->tikzpicture环境中移除到path命令将解决问题。

在此处输入图片描述

代码

\documentclass{llncs}
\usepackage{llncsdoc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning,pgfplots.groupplots}
\usepackage{circuitikz}

\begin{document}
\tikzset
{
        treenode/.style = {circle, draw=black, align=center, minimum size=1cm},
        subtree/.style  = {isosceles triangle, draw=black, align=center, minimum height=0.5cm, minimum width=1cm, shape border rotate=90, anchor=north}
}
\begin{figure}[t]
\centering
\caption{A binary tree. \label{fig:simple}}
{
    \begin{tikzpicture}[scale=0.6, transform shape]
        %-----------------------------------------------------------------------
        \node (x)[treenode]                                 at (-3,0)       {$X$ \\ 100};
        \node (y)[treenode, fill=black!20]  at (-4.5,-1.5)  {$Y$ \\ 50};
        \node (a)[subtree]                                  at (-1,-1)      {\Large $\alpha$};
        \node (b)[subtree]                                  at (-6,-2.5)    {\Large $\beta$};
        \node (gnd)[ground]                                 at (-2.5,-2.5)  {}; 

        \path[->,every node/.style={font=\sffamily\small}]
        (-3, 1) edge node                   {} (x)
        (x)         edge node                   {} (y)
        (x)         edge node                   {} (a.north)
        (y)         edge node                   {}(b.north)
        (y)         edge node                   {}(gnd);
        %-----------------------------------------------------------------------
    \end{tikzpicture}
}
\end{figure}
\end{document}

相关内容