我尝试在乳胶中获取此树结构,但找不到任何示例。有人能帮助我吗?
[ ]
答案1
直接使用 TikZ 绘制并使用 tikzlibrary positioning
:
\documentclass[border=3mm, tikz ]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (a);
\coordinate[right=33mm of a] (b);
\coordinate[above right=11mm and 22mm of b] (c);
\draw (a) -- node[above] {2} + (150:22mm) node[left] {2};
\draw (a) -- node[below] {2} + (210:22mm) node[left] {4};
%
\draw (a) -- node[above] {1} (b)
-- node[above] {0.5} (c)
-- node[above] {1} + (30:12mm) node[right] {3};
\draw (c) -- node[below] {4} + (12mm,0) node[right] {5};
\draw (b) -- node[below] {1} + (330:22mm) node[right] {1};
\end{tikzpicture}
\end{document}
答案2
graphs
这是使用和库的版本graphdrawing
。它需要使用 LuaLaTeX 进行编译。
\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{graphs,quotes,graphdrawing}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}[every edge quotes/.append style={midway, auto, font=\scriptsize, inner sep=1.5pt}]
\graph [layered layout, horizontal=a to b] {
{2 [<"2"], 4[<"2"']} -- a/"" -- ["1"] b/"" -- {c/"" [>"0.5"] -- {3 [>"1"], 5 [>"4"']}, 1 [>"1"']}
};
\draw (2) -- (a.center) -- (4) (a.center) -- (b.center) -- (c.center) (b.center) -- (1) (c.center) -- (3) (c.center) -- (5);
\end{tikzpicture}
\end{document}
需要最后一个\draw
命令只是因为我无法弄清楚如何正确地将空节点合并到图中。希望有人能发表评论并给我一个指向手册相关部分的指针!(答案可能是我应该真正以不同的方式指定图表本身 - 我不确定。)
答案3
以下是一段简短的代码pst-tree
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}%
\usepackage{lmodern}
\usepackage{ pst-tree}
\usepackage{auto-pst-pdf}
\pagestyle{empty}
\begin{document}
\psset{treesep=1.8cm, nodesepB=4pt, levelsep=1.8cm, tpos=0.4}
\[ \begin{psmatrix}[shortput=nab, colsep=3cm]
\pstree[treemode=L] {\Tp{\pnode{R1}}}{{\psset{tpos=0.5}\Tr{2}_{\scriptstyle2}}\Tr{4}_{\scriptstyle2}} & \pstree[treemode=R, nodesepB=0pt] %
{\Tp{\pnode{R2}}}{\pstree[treesep=1.8cm, nodesepB=4pt]{\Tp^{\scriptstyle0.5}} {\Tr{3}^{\scriptstyle1}\Tr{5}_{\scriptstyle4}}%
\Tr{\ 1}_{\scriptstyle1}}
\ncline[nodesepB=0pt]{R1}{R2}\naput{\scriptstyle1}
\end{psmatrix} \]
\end{document}