我想在树的边缘添加标签 3、4、5,就像您在图片上看到的那样,但我不知道如何做 :(
我的最小例子:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[sibling distance=40pt]
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\Tree [.\textrm{} [.$x_2=1$ ]
[.$x_2\neq1$ [.$x_2=2$ ]
[.$x_2\neq2$ [.$x_2=3$ ]
[.$x_2=4$ ] ] ] ]
\end{tikzpicture}
\end{center}
\end{document}
答案1
我不知道如何使用tikz-qtree
,但使用 TikZ,这很容易:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[sibling distance=150pt]
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-17pt)
-| (\tikzchildnode)}}}
\coordinate
child {node {$x_2=1$} edge from parent node[auto,swap,pos=0.08] {3}}
child {node {$x_2\neq1$}
child {node {$x_2=2$} edge from parent node[auto,swap,pos=0.08] {4}}
child {node {$x_2\neq2$}
child {node {$x_2=3$} edge from parent node[auto,swap,pos=0.08] {5}}
child {node {$x_2=4$}}
}
};
\end{tikzpicture}
\end{center}
\end{document}