如何为 tikz 添加空间?我想在 1 和 2 之间以及 2 和 3 之间添加空间

如何为 tikz 添加空间?我想在 1 和 2 之间以及 2 和 3 之间添加空间
\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{trees}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
    \node {One}[edge from parent fork right, grow'=right, align=right]
        child { node(yongnian) {1}
               child {node(xixiang){11}
                   child {node{111}
                        child {node{111}
                          child {node{111}}}}
                   }
               child {node(xihui)[below of=xixiang]{222}}
                child {node(xifu)[below of=xihui]{222}}
                 child {node(xilu)[below of=xifu]{222}}
               }
        child { node(qingnian)[below of=yongnian] {2}
            child {node{Me}}
            child {node{My}}
            }   
        child { node (shengnian)[below of=qingnian] {3}
             child {node{Josh}}
             child {node{arah}}
            }   
     child { node(fengnian)[below of=shengnian] {4}
             child {node{sh}}
             child {node{arah}}
            }           
    ;
\end{tikzpicture}

\end{document} 

答案1

添加适当的sibling distance距离

level 1/.style={sibling distance=1in},
level 2/.style={sibling distance=1cm},

此外,您不需要below of=这里的所有这些东西。作为库的附注,positioning它应该是below = of

代码:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{trees}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
level 1/.style={sibling distance=1in},
level 2/.style={sibling distance=1cm},
grow'=right, align=right
  ]
    \node {One}[edge from parent fork right]
        child { node(yongnian) {1}
               child {node(xixiang){11}
                   child {node{111}
                        child {node{111}
                          child {node{111}}}}
                   }
               child {node(xihui){222}}
                child {node(xifu){222}}
                 child {node(xilu){222}}
               }
        child { node(qingnian) {2}
            child {node{Me}}
            child {node{My}}
            }
        child { node (shengnian) {3}
             child {node{Josh}}
             child {node{arah}}
            }
     child { node(fengnian) {4}
             child {node{sh}}
             child {node{arah}}
            }
    ;
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容