# Treating psTree object as a figure

I created the following probability tree diagram using psTree then running XeLaTeX in texmaker.

\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}


I want to treat the tree diagram as a figure in my LaTeX document, but I'm stuck.

What I've been doing is taking a screenshot of the tree diagram in the preview box of texmaker, then inserting it into a LaTeX document by doing something like this

\begin{figure}[pngfile]
\caption{Tree Diagram}
\centering
\includegraphics[width=0.5\textwidth]{pngfile}
\end{figure}


Could you recommend a better way?

• you can just replace the center env in your original by \begin{figure}\caption{tree diagram}.. \end{figure} – David Carlisle Oct 11 '14 at 14:50
• @DavidCarlisle: It works! The solution was easier than I thought. Thank you!!! – Maria Reyes Oct 11 '14 at 15:02

## Step 1:

Create the diagram.

% 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}


## Step 2:

Import the diagram from within the main document.

% 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}


• Thank you for your help. I like this solution very much. – Maria Reyes Oct 12 '14 at 13:25
• @MariaReyes: It is actually the recommended best practice approach. "Separation of concern" : Separating each diagram from the main document. :-) Don't forget to vote it up (optional). – kiss my armpit Oct 12 '14 at 13:29