如何在我的树形图中添加一片叶子?

如何在我的树形图中添加一片叶子?
\documentclass{article}
\usepackage{qtree}
\begin{document}
\Tree [.X leaf_1 [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
\end{document}

我想在 leaf_1 下添加一个叶子和节点。我该怎么做?

还有一个问题,我怎样才能编写与图表平行的文本?

节点周围是否可以有框架,就像圆形节点一样?

我正在尝试创建类似的东西

我正在尝试创建类似的东西

编辑2:我尝试通过删除学生节点和链接到它的所有叶子来修改它,但是我的代码出现错误,

\begin{forest}
  shade me/.style={%
    bottom color=#1!25,
    top color=#1!5,
    draw=#1,
    drop shadow,
    font=\sffamily,
  },
  my label/.style n args=2{%
    edge label={node [midway, black, font=\sffamily\scriptsize, #1] {#2}}
  },
  where n children=0{%
    shade me=blue!50!cyan,
  }{%
    if level=0{%
      shade me=green!75!gray,
    }{%
      shade me=blue!75!magenta,
    }
  },
  for tree={%
    delay={content/.wrap value={\strut #1}},
    edge={red,->},
    l sep+=25pt,
    s sep+=20pt
  }
  [Debt
  [Age, my label={above, sloped}{High}
      [No, my label={above, sloped}{$< 30$}]
      [Yes, my label={above, sloped}{$31\dots 40$}]
    ]

    [CR, my label={above, sloped}{Low}
      [Yes, my label={above, sloped}{Fair}]
      [Age, my label={above, sloped}{Excellent}
        [No, my label={above, sloped}{$> 40$}]
        [Yes, my label={above, sloped}{$31\dots 40$}]]
      ]
    ]

\end{forest}

答案1

你想要这个吗?

附加叶和节点

\documentclass{article}
\usepackage{qtree}
\begin{document}
\Tree [.X [.leaf_1 leaf_4 node ] [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
\end{document}

对于更漂亮的树,您需要一个更漂亮的包。以下是使用 Forest 的示例:

更漂亮的树

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shadows}
\begin{document}
\begin{forest}
  shade me/.style={%
    bottom color=#1!25,
    top color=#1!5,
    draw=#1,
    drop shadow,
    font=\sffamily,
  },
  my label/.style n args=2{%
    edge label={node [midway, black, font=\sffamily\scriptsize, #1] {#2}}
  },
  where n children=0{%
    shade me=blue!50!cyan,
  }{%
    if level=0{%
      shade me=green!75!gray,
    }{%
      shade me=blue!75!magenta,
    }
  },
  for tree={%
    delay={content/.wrap value={\strut #1}},
    edge={red,->},
    l sep+=25pt,
    s sep+=20pt
  }
  [Income
  [Age, my label={above, sloped}{High}
      [No, my label={above, sloped}{$< 30$}]
      [Yes, my label={above, sloped}{$31\dots 40$}]
    ]
    [Student, my label={}{Medium}
      [Age
        [No, my label={above, sloped}{$< 30$}]
        [Yes, my label={above, sloped}{$31\dots 40$}]
        [CR, my label={above, sloped}{$> 40$}
          [Yes, my label={above, sloped}{Fair}]
          [No, my label={above, sloped}{Excellent}]
        ]
      ]
      [Yes]
    ]
    [CR, my label={above, sloped}{Low}
      [Yes, my label={above, sloped}{Fair}]
      [Age, my label={above, sloped}{Excellent}
        [No, my label={above, sloped}{$> 40$}]
        [Yes, my label={above, sloped}{$31\dots 40$}]]
      ]
    ]
  ]
\end{forest}
\end{document}

相关内容