这是我目前所得到的。垂直点超出了两个边缘。我希望它们在到达边缘之前就结束。
\documentclass[fleqn]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{tikz}
\usepackage{cancel}
\usepackage{color}
\usepackage{polynom}
\usepackage{graphicx}
\usepackage{fouriernc}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{listing}
\usepackage{qtree}% For drawing trees.
\usepackage{pstricks,pst-node,pst-tree,pstricks-add}%This might be better.
\title{Trees}
\author{G}
\date{\today}
\begin{document}
\maketitle
{\pstree[treemode=R,levelsep=3.5]{\Tdot*[name=A] \taput{$\emptyset$}}{
\pstree[treemode=R, levelsep=3.5]{\Tdot*[name=B]\taput{$p_{1}$}}{%
{\pstree[treemode=R,levelsep=3.5]{\Tdot*[name=C]\taput{$p_{1}$}}% %
{\Tdot*[name=D]~{\dots}\taput{$p_{1}$} \Tdot*[name=E]~{\dots}\tbput{$p_{2}$}}}
{\pstree[treemode=R,levelsep=3.5]{\Tdot*[name=F]\tbput{$p_{2}$}}% %
{\Tdot*[name=G]~{\dots}\taput{$p_{1}$} \Tdot*[name=H]~{\dots}\tbput{$p_{2}$}}}}
\pstree[treemode=R, levelsep=3.5]{\Tdot*[name=I]\tbput{$p_{2}$}}{%\vdots
{\pstree[treemode=R,levelsep=3.5]{\Tdot*[name=J]\taput{$p_{1}$}}% %
{\Tdot*[name=K]~{\dots}\taput{$p_{1}$} \Tdot*[name=L]~{\dots}\tbput{$p_{2}$}}}
{\pstree[treemode=R,levelsep=3.5]{\Tdot*[name=M]\tbput{$p_{2}$}}% %
{\Tdot*[name=N]~{\dots}\taput{$p_{1}$} \Tdot*[name=P]~{\dots}\tbput{$p_{2}$}}}}
}}
\ncline[linestyle=dotted,nodesep=1.5mm,offset=1cm]{I}{B}
\end{document}
答案1
这是一种方法。我删除了不必要的包。请注意,它不会对pdflatex
和产生任何结果auto-pst-pdf
,但对 和 有效xelatex
,当然对 也有效latex
:
\documentclass[fleqn]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb,amsfonts}
\usepackage{fouriernc}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{pst-tree,pstricks-add}%This might be better.
\title{Trees}
\author{G}
\date{\today}
\pagestyle{empty}
\begin{document}
\maketitle
\clearpage
\psset{treemode=R, levelsep=3.5}
\pstree{\Tdot*[name=A] \taput{$\varnothing$}}{%
\pstree{\Tdot*[name=B]\taput{$p_{1}$}\ncput[npos=0.7]{\rnode{X}{}}}{%
{\pstree{\Tdot*[name=C]\taput{$p_{1}$}}% %
{\Tdot*[name=D]~{$ \cdots $}\taput{$p_{1}$} \Tdot*[name=E]~{$ \cdots $}\tbput{$p_{2}$}}}
{\pstree{\Tdot*[name=F]\tbput{$p_{2}$}}% %
{\Tdot*[name=G]~{$ \cdots $}\taput{$p_{1}$} \Tdot*[name=H]~{$ \cdots $}\tbput{$p_{2}$}}}}
\pstree{\Tdot*[name=I]\tbput{$p_{2}$} \ncput[npos=0.7]{\rnode{Y}{}}}{%\vdots
{\pstree{\Tdot*[name=J]\taput{$p_{1}$}}% %
{\Tdot*[name=K]~{$ \cdots $}\taput{$p_{1}$} \Tdot*[name=L]~{$ \cdots $}\tbput{$p_{2}$}}}
{\pstree{\Tdot*[name=M]\tbput{$p_{2}$}}% %
{\Tdot*[name=N]~{$ \cdots $}\taput{$p_{1}$} \Tdot*[name=P]~{$ \cdots $}\tbput{$p_{2}$}}}}
}
\ncline[linestyle=dotted,nodesep=2pt]{X}{Y}%
\end{document}
答案2
只是为了好玩,这里有一个森林版本。请注意,实际的树规范非常简洁:
[
[, tikz={
\draw [dotted] ($()!1/3!(!u)$) -- ($(!s)!1/3!(!u)$);
}
[[][]]
[[][]]
]
[
[[][]]
[[][]]
]
]
该tikz
位负责绘制垂直虚线。
其他一切都是在样式的规范中完成的,包括标签的设置、节点和间距的自定义以及右侧点的添加。
代码:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest,amssymb}
\usetikzlibrary{calc}
\begin{document}
\begin{forest}
for tree={
grow=0,
inner sep=0pt,
minimum width=2.5pt,
fill,
draw,
circle,
s sep+=5pt,
l+=15pt,
if level=0{
label={[font=\scriptsize]above:$\varnothing$}
}{
if n=1{
edge label={node [below, midway, font=\scriptsize] {$p_2$} }
}{
edge label={node [above, midway, font=\scriptsize] {$p_1$} }
}
},
if n children=0{
append={[, l-=25pt, edge={dotted}]}
}{}
}
[
[, tikz={
\draw [dotted] ($()!1/3!(!u)$) -- ($(!s)!1/3!(!u)$);
}
[[][]]
[[][]]
]
[
[[][]]
[[][]]
]
]
\end{forest}
\end{document}
结果: