TIKZ 树:改变节点之间的角度

TIKZ 树:改变节点之间的角度

我正在努力寻找如何更改 tikz 树中节点之间的角度。我已经尝试过sibling angle=...专门针对子节点的属性或作为level 1/.style=...\tikzpicture 环境开头的属性。Sibling distance对我来说有效,但Sibling angle没有改变任何东西。看下面的例子:

我想要的是 B 和 C 之间的角度变宽或变窄。对于较大的树,如果重叠较多,我需要这样做。

代码:

\documentclass{article}    
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}

%------------------ Tikz Settings----------------------------    
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

%Define tree diagram styles   
\tikzstyle{Decision} = [shape=rectangle,
                        draw,
                        double=black,
                        double distance=1pt,
                        text=black]
\tikzstyle{Lottery} = [shape=circle,
                        draw,
                        double=black,
                        double distance=1pt,
                        text=black]
\tikzstyle{Outcome}     = [circle,
                       minimum width=3pt,
                       fill, 
                       inner sep=0pt]

\begin{document}   
        \begin{figure}
                \centering                  
                \begin{tikzpicture}[grow=right, sloped, scale=0.7,level 1/.style={sibling angle=60, sibling distance=60mm}]         
                \node [Decision,label=left:{}] {A}
                [node distance = 100mm]
                child[sibling angle=10]{ 
                    node[Decision,label=right:{}] {B}
                        edge from parent
                        node[above] {}
                    }
                child{ 
                    node[Decision,label=right:{}] {C}
                    edge from parent
                    node[above] {}
                };      
                \end{tikzpicture}                       
        \end{figure}
\end{document}

答案1

如果你准备使用森林,您可以用各种方式指定兄弟节点与其父节点之间的角度等。但请注意森林在自动调整这些事情方面相当出色,因此您可能不需要手动设置它们。

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\tikzset{
  Decision/.style = {%
    draw,
    line width=1.4pt
  },
  Lottery/.style = {%
    draw,
    line width=1.4pt
  },
  Outcome/.style = {%
    circle,
    minimum width=3pt,
    fill,
    inner sep=0pt
  }
}

\begin{document}
\begin{forest}
  for tree={
    grow=0,
    Decision,
    calign angle=60,
    calign=fixed edge angles,
  }
  [A
    [B, calign secondary angle=80, calign primary angle=-60
      [D]
      [E]
    ]
    [C, calign secondary angle=70, calign primary angle=-60
      [F]
      [G]
    ]
  ]
\end{forest}

\end{document}

树上的角度

相关内容