# Image undesired displacement using pstricks

The following code:

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb,xcolor}
\usepackage{pst-all}
\usepackage{lipsum}
%\usepackage{pstricks}
\begin{document}
\lipsum[1-2]
\begin{pspicture}
\psset{unit=1.5,linewidth=0.7mm,linecolor=red,fillstyle=solid,fillcolor=yellow}
%,showpoints=true,dotsize=0.2}
\pspolygon(0,1.21)(2,1.21)(0.38,0)(1,2)(1.62,0)
\end{pspicture}
\vskip\baselineskip
The \rnode{A}{dog} has eaten \rnode{B}{his} bone.
\ncbar[angle=-90,nodesep=3pt,arm=.3]{->}{B}{A}
\end{document}


yields:

Why is the image displaced to the bottom of the page? Usually in TiKZ, which by the way I use more often, I just write the code and the image appears where it is supposed to be. How can I correct this?

-

You need to specify the canvas size in advance. Canvas unit and graphics object unit should be set such that the graphics object lies inside the canvas.

\documentclass[a6paper]{article}
\usepackage{geometry}
\usepackage{pst-node}
\usepackage{lipsum}

\begin{document}
\lipsum[1-2]
\bgroup
\psset{unit=1.5}
\begin{pspicture}(2,2)
\pspolygon[linewidth=0.7mm,linecolor=red,fillstyle=solid,fillcolor=yellow]
(0,1.21)(2,1.21)(0.38,0)(1,2)(1.62,0)
\end{pspicture}
\egroup
\vskip\baselineskip
The \rnode{A}{dog} has eaten \rnode{B}{his} bone.
\ncbar[angle=-90,nodesep=3pt,arm=.3]{->}{B}{A}
\end{document}


-
Is there a way to get pspicture to adapt its size automatically to fit its contents (like tikzpicture does)? –  Jake Nov 28 '12 at 17:42
@Jake: It is impossible. :-) –  stalking is prohibited Nov 28 '12 at 17:44
@GarbageCollector Any other advices about pstricks? Like what packages to load, technicalities,..... –  azetina Nov 28 '12 at 20:12
@GarbageCollector Is there another way of doing away with the \bgroup and \egroup? –  azetina Nov 28 '12 at 20:27
@azetina: There are many packages and to know which one to load we have to know them in advance. You can use { and } instead of \bgroup and \egroup. Grouping is needed to localize the effect of \psset settings. –  stalking is prohibited Nov 28 '12 at 23:41

This is much in line with what GarbageCollector suggested. I would just point out that the pspicture environment can take two coordinates to specify the lower left hand corner and upper right hand corner. Also, I would put the \psset{...} outside the environment. If you don't want it to take universal effect, place it all inside parentheses (see MWE below).

pstricks has some nice features such as showgrid=true. Also by playing with the two coordinates you can get pstricks to overlay (or underlay) its image depending on where the image is placed.

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb,xcolor}
\usepackage{pst-all}
\usepackage{lipsum}
\begin{document}

{\psset{unit=1.5,linewidth=0.7mm,linecolor=red,fillstyle=solid,fillcolor=yellow}
\begin{pspicture}(-3,2)(-3,2)
\pspolygon(0,1.21)(2,1.21)(0.38,0)(1,2)(1.62,0)
\end{pspicture}}
\lipsum[1-2]

{\psset{unit=1.5,linewidth=0.7mm,linecolor=red,fillstyle=solid,fillcolor=yellow}
\begin{pspicture}[showgrid=true](0,0)(2,2)
\pspolygon(0,1.21)(2,1.21)(0.38,0)(1,2)(1.62,0)
\end{pspicture}}
\vskip\baselineskip
The \rnode{A}{dog} has eaten \rnode{B}{his} bone.
\ncbar[angle=-90,nodesep=3pt,arm=.3]{->}{B}{A}
\end{document}


Regarding what other packages you might find useful, that's hard to say without knowing what you want to accomplish. I often use pst-eucl for drawing various geometry shapes (I teach a geometry course). There are other more powerful means of drawing shapes, what I like about pst-eucl is that the commands are more in line with how you would do constructions.

I've recently being trying to teach myself tikz. There is a lot that tikz can apparently do and in a more user friendly way than pstricks: in fact, occasionally pstricks can be rather obscure. For example, labeling node connectors can be done in pstricks but it seems to me that the method of doing this in tikz is cleaner and more transparent.

What is nice about pstricks---that I am particularly fond of---is the ability to embed post-script commands within it.

-