2

I'm having trouble positioning a psframe inside a page with a specific size and it looks like the whole pspicture is shifted in the page. This is a MWE of my code

\documentclass[border={0pt 0pt 0pt 0pt}]{standalone}

\usepackage[english]{babel}
\usepackage{pstricks-add}
\usepackage[paperheight=16cm,paperwidth=21cm]{geometry}


\pagestyle{empty}

\begin{document}

\psset{algebraic,xunit=1cm,yunit=1cm}

\begin{pspicture}(0,0)(21,16)

\psframe[fillstyle=solid,fillcolor=blue!20,linewidth=3pt,linecolor=black](0,0)(21,16)

\end{pspicture}

\end{document}

As you can see, my page is 21cm wide and 16cm tall. My pspicture has the coordinates (0,0)(21,16) and the xunit and yunit are set to 1cm. My psframe has the same coordinates as the pspicture so what I was expecting once this code is compiled is to have a blue, 16cm x 21cm page with a black frame around it. Instead, what I'm getting is a page with the desired dimensions but the blue background is shifted a bit to the right and up another bit, leaving a white area exposed.

How does pspicture positioning work? How can I fix this code? I can manually shift the frame but I would like a more elegant solution because it seems to me that there is something wrong, or perhaps something missing from this code.

1

I'd use article and add the following:

  • margin=0pt for geometry which makes the text block match the paper size;

  • \noindent before the pspicture environment.

    The pspicture environment is set like any other textual component (like the letter a, or the number 7. As such, it also is indented with \parindent when it starts a paragraph. The width of this "big character" will be 21cm and have a height of 16cm, exactly what you want.

enter image description here

\documentclass{article}

\usepackage{pstricks-add}
\usepackage[paperheight=16cm,paperwidth=21cm,margin=0pt]{geometry}

\pagestyle{empty}

\begin{document}

\psset{algebraic,xunit=1cm,yunit=1cm}

\noindent
\begin{pspicture}(0,0)(21,16)

\psframe[fillstyle=solid,fillcolor=blue!20,linewidth=3pt,linecolor=black](0,0)(21,16)

\end{pspicture}

\end{document}
| improve this answer | |
  • Thank you very much, Werner. One more thing, if I may... do you know why the standalone class did not work? – Gabu Mar 13 '17 at 20:07
  • 1
    @Gabu: I know standalone has a specific interface dedicated to pstricks and tikz (supplied during class load: \documentclass[pstricks]{standalone} or \documentclass[tikz]{standalone}) which might mean its interface with those environments are treated differently to what you think. I don't really use standalone, so I'm not that familiar with the inner workings. – Werner Mar 13 '17 at 20:19
0

Do not use package geometry when using standalone and run it with xelatex:

\documentclass[pstricks,border={0pt 0pt 0pt 0pt}]{standalone}
\usepackage{pstricks-add}
\begin{document}

\begin{pspicture}(0,0)(21,16)   
\psframe[fillstyle=solid,fillcolor=blue!20,linewidth=3pt](0,0)(21,16)   
\end{pspicture}

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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