Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a strange problem witih PSTricks, pst-tree and the pspicture environment. I use a figure float and a simple tree. When I put a pspicture environment around it, the picture is placed above the text. What am I doing wrong?

Note: when I remove the pspicture environment, everything is working fine. But without the pspicture environment, I can't use things like the psbrace.

Wrong output

\documentclass[english]{article}


\usepackage{pst-plot}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{pst-tree}
\usepackage{pstricks-add}


\begin{document}
    Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem
    ipsum. 

    \begin{figure}
        \begin{pspicture}(3,3)
        \pstree{\Tcircle{ }}
          {
            \pstree{\Tr{ }}{\Tfan}
            \pstree{\Tr{ }}{\Tfan}
          }
        \end{pspicture}

        \caption{}
    \end{figure}

    Lorem ipsum. Lorem ipsum. Lorem ipsum. 

\end{document}
share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

This is happening because the contents of your pspicture are extending outside of its bounds.

If you add the line \psgrid immediately after your \begin{pspicture}, you'll see that you get

screenshot

There are many ways to fix this- the easiest is perhaps to change the viewing window of your pspicture, to something like

\begin{pspicture}(5,-5)

screenshot

The general syntax is

\begin{pspicture}(xmin,ymin)(xmax,ymax)

In addition to this, you'll probably want to add \centering to your environment. The complete code follows for your reference.

\documentclass{article}

\usepackage{pst-tree}

\begin{document}
Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem
ipsum. 

\begin{figure}
   \centering
   \begin{pspicture}(5,-5)
   \psgrid
   \pstree{\Tcircle{ }}
         {
           \pstree{\Tr{ }}{\Tfan}
           \pstree{\Tr{ }}{\Tfan}
         }
   \end{pspicture}
   \caption{}
\end{figure}

Lorem ipsum. Lorem ipsum. Lorem ipsum. 

\end{document}

Once you're done with construction, simply comment out the \psgrid line, and you'll be finished.

share|improve this answer
    
Great answer. You'll have to wait for an up-vote. –  Werner Feb 6 '12 at 22:27
    
@Werner Thanks, that's high praise indeed from a guru :) –  cmhughes Feb 6 '12 at 22:29
    
Thanks a lot for your answer! I had the idea to enable the grid to see what's going on, but I didn't think of setting negative values. But this means, I have to know size of the tree in advance? –  lumbric Feb 6 '12 at 23:09
    
@lumbric During construction, I think the answer is typically, yes. You can use pspicture* which will automatically clip the picture, but that's probably not what you want. –  cmhughes Feb 7 '12 at 0:24
1  
@lumbric I tend to think of the pspicture environment as the 'bounding box' for the picture. Without the environment, PSTricks will do its best to figure out the 'bounding box' on its own- as you've described, sometimes it will work, but you may not be able to use all commands. –  cmhughes Feb 7 '12 at 16:08
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.