图形节点间距和注释

图形节点间距和注释

我希望自动为该 latex 代码中的节点留出间隙,使它们不重叠。我有许多图表要做,所以理想情况下不想插入大量空白来将它们隔开。请问有没有什么巧妙的方法可以做到这一点?我尝试添加node distance=3cm和,5cm[]没有帮助。

代码:

\begin{tikzpicture}[nodes={draw, circle}, -]

\node{${aaa}$}
    child { node {${aaa}$} 
        child { node {${aaa}$} 
            child { node{${aaa}$} } 
    child { node{${aaa}$} } }
        child { node {${aaa}$} } }
    child { node {${aaa}$}
            child { node{${aaa}$}
    child { node{${aaa}$} } }
        child { node {${aaa}$} } } ;
\end{tikzpicture}

答案1

使用forest基于 TikZ 包的包很简单:

enter image description here

\documentclass[margin=5mm]{standalone}
\usepackage[edges]{forest}

\begin{document}
   \begin{forest}
    for tree={% style of tree nodes
      draw, semithick,
      shape = circle,
              % style of tree (edges, distances)
       edge = {draw, semithick},
      s sep = 8mm,    % minimum sibling distance between nodes at any tree level
               }
[${aaa}$
    [${aaa}$
        [${aaa}$
            [${aaa}$]
            [${aaa}$]
        ]
        [${aaa}$]
    ]
    [${aaa}$
        [${aaa}$
            [${aaa}$]
        ]
        [${aaa}$]
    ]
]
    \end{forest}
\end{document}

使用纯 TikZ 树,您需要手动确定适当的兄弟距离(与森林相比,不是任何级别的节点之间的最小距离,而是每个级别/需要的地方/分别确定):

enter image description here

\documentclass[tikz, margin=5mm]{standalone}

 \begin{document}
    \begin{tikzpicture}[nodes={draw, circle},
level 1/.style = {sibling distance=33mm}, % increased
level 2/.style = {sibling distance=22mm}, % decreased,
                        ]
\node{${aaa}$}
    child { node {${aaa}$}
        child { node {${aaa}$}
            child { node{${aaa}$} }
    child { node{${aaa}$} } }
        child { node {${aaa}$} } }
    child { node {${aaa}$}
            child { node{${aaa}$}
    child { node{${aaa}$} } }
        child { node {${aaa}$} } } ;
    \end{tikzpicture}
\end{document}

相关内容