![将 psTree 对象视为图形](https://linux22.com/image/299455/%E5%B0%86%20psTree%20%E5%AF%B9%E8%B1%A1%E8%A7%86%E4%B8%BA%E5%9B%BE%E5%BD%A2.png)
我使用 psTree 创建了以下概率树形图,然后在 texmaker 中运行 XeLaTeX。
\documentclass[12pt]{article}
\usepackage{graphics,graphicx}
\usepackage{pstricks,pst-node,pst-tree}
\psset{treemode=R}
\begin{center}
\psTree{\Tcircle{16}}
\pstree{\Tcircle{11}\taput{$\frac{1}{2}$}}
{{\Tcircle{12}}\taput{$\frac{1}{2}$} {\Tcircle{13}}\tbput{$\frac{1}{2}$}}
\pstree{\Tcircle{15}\tbput{$\frac{1}{2}$}}
{\Tcircle{14}}\tbput{$1$}
\endpsTree
\end{center}
\end{document}
我想将树形图作为 LaTeX 文档中的图形,但我遇到了困难。
我一直在做的是截取 texmaker 预览框中的树形图的屏幕截图,然后通过执行以下操作将其插入到 LaTeX 文档中
\begin{figure}[pngfile]
\caption{Tree Diagram}
\centering
\includegraphics[width=0.5\textwidth]{pngfile}
\end{figure}
您能推荐一个更好的方法吗?
答案1
步骤1:
创建图表。
% filename: diagram.tex
% compile it with the following sequence to get diagram.pdf
% latex diagram
% dvips diagram
% ps2pdf -dAutoRotatePages=/None diagram.ps
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-tree}
\psset{treemode=R}
\begin{document}
\psTree{\Tcircle{16}}
\pstree{\Tcircle{11}\taput{$\frac{1}{2}$}}
{{\Tcircle{12}}\taput{$\frac{1}{2}$}{\Tcircle{13}}\tbput{$\frac{1}{2}$}}
\pstree{\Tcircle{15}\tbput{$\frac{1}{2}$}}
{\Tcircle{14}}\tbput{$1$}
\endpsTree
\end{document}
第2步:
从主文档中导入图表。
% filename: main.tex
% compile it with pdflatex thrice (probably more) to make the cross-referencing work properly
% pdflatex -draftmode -interaction=batchmode main
% pdflatex -draftmode -interaction=batchmode main
% pdflatex main
\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
In PSTricks we trust, how about you?
\begin{figure}
\centering
\includegraphics{diagram}
\caption{PSTricks is fun}
\label{fig:diagram}
\end{figure}
See Fig~\ref{fig:diagram} on page~\pageref{fig:diagram}
\end{document}