强制 TikZ 节点最小大小

强制 TikZ 节点最小大小

我有一个由许多未标记节点组成的树结构。但是,由于某种原因,这些节点比我想要的要大得多,并且似乎有一个最小大小,低于这个最小大小时,键minimum size将被忽略:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
  \begin{tikzpicture}[root/.style={draw,diamond, minimum size=1mm},
                      branch/.style={draw,rectangle},
                      leaf/.style={draw,circle, minimum size=1mm},
                      level 1/.style={sibling distance=5.5em, level distance=1.5em},
                      level 2/.style={sibling distance=2em},
                      level 3/.style={sibling distance=1.5em}]
 \node [root] {}
  child { node[branch] {}
   child { node[leaf] {} }
   child { node[branch] {}
    child { node[leaf] {} }
    child { node[leaf] {} }
   }
  }
  child { node[branch] {}
   child { node[leaf] {} }
   child { node[leaf] {} }
   child { node[leaf] {} }
  }
  child { node[branch] {}
   child { node[branch] {}
    child { node[leaf] {} }
    child { node[leaf] {} }
    child { node[leaf] {} }
   }
   child { node[leaf] {} }
   child { node[leaf] {} }
  }
  child { node[branch] {}
   child { node[leaf] {} }
   child { node[branch] {}
    child { node[leaf] {} }
    child { node[leaf] {} }
   }
   child { node[leaf] {} }
 };
\end{tikzpicture}
\end{document}

root尽管和键的最小尺寸leaf很小,但节点仍然相对较大。

答案1

您还需要inner sep=2pt根据想要的大小进行调整。

因此,请按如下方式调整您的风格:

  \begin{tikzpicture}[root/.style={draw,diamond, minimum size=1mm,inner sep=2pt},
                      branch/.style={draw,rectangle,inner sep=2pt},
                      leaf/.style={draw,circle, minimum size=1mm,inner sep=2pt},
                      level 1/.style={sibling distance=5.5em, level distance=1.5em},
                      level 2/.style={sibling distance=2em},
                      level 3/.style={sibling distance=1.5em}]
  ...

在此处输入图片描述

相关内容