如何更改 TikZ 树中的角度

如何更改 TikZ 树中的角度

如何改变 Tikz 树中的角度?

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=2cm},
every node/.style={draw,circle},
edge from parent/.style={draw,latex-, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}}]
\node {7}
child {node {6}}
child {node {5}
child {node {2}}
}
child {node {4}
child {node {3}}
child {node {1}
child {node {0}}
}
};
\end{tikzpicture}

我的代码输出:

我的代码输出

但我想要这个:

期望输出

答案1

使用该库可以相当方便地绘制此类图表graphs,从而可以相当直接地定义增长风格。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{graphs}
\tikzgraphsset{grow down left/.style={
    placement/place,
    chain shift={(-#1,-#1)},
    @auto anchor horizontal=center,
    placement/logical node width/.code=\def\pgfmathresult{1}
  },
  grow down left/.default=1,
  phantom/.style={target edge style={opacity=0},opacity=0}}
\begin{document}
\begin{tikzpicture}[a/.style={-latex,green!60!black}]
  \graph [edges={green!60!black,>=latex},
    nodes={circle,draw=green!60!black,fill=green!30},
    grow down left,
    branch left=1cm] { 7<- {
    6,
    5 <- {
      2
    },
    9 [phantom],
    4 <- {
        3,
        1 <- {0}} }
};
\end{tikzpicture}    
\end{document}

在此处输入图片描述

相关内容