5

I test my figures in an standalone file, and when I obtain what I want, I pass to my main file with text.

How can I do to adapt the size?

Because, sometimes I want to put 3 images in a row and I need to resize the original pstricks pictures.

Suppose this code typed by Herbert in other post:

\documentclass{article}
\usepackage{pstricks}
\newpsobject{pslineA}{psline}{linewidth=6\pslinewidth, linecolor=green}
\newpsobject{pslineB}{psline}{linewidth=10\pslinewidth, linecolor=red}

\begin{document}
\begin{pspicture}(5,5)
  \psline(0,1)(5,1)
  \psline[linewidth=1mm](0,2)(5,2)
  \pslineA(0,3)(5,3)
  \pslineB(0,4)(5,4)
\end{pspicture}
\end{document}

Are there any easy way with psset/xunit/yunit?

I thought that changing numbers in

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

I could obtain what I want, but... no! I change this values and the picture is with the same length.

1
  • there's a psgraph environment that allows you to specify the width and height
    – cmhughes
    Apr 15, 2014 at 16:22

4 Answers 4

8

Changing the units (unit itself and linewidth) does resize the image:

\documentclass{article}

\usepackage[pdf]{pstricks}
\newpsobject{pslineA}{psline}{linewidth=6\pslinewidth, linecolor=green}
\newpsobject{pslineB}{psline}{linewidth=10\pslinewidth, linecolor=red}

\begin{document}

\begin{pspicture}(5,5)
  \psline(0,1)(5,1)
  \psline[linewidth=1mm](0,2)(5,2)
  \pslineA(0,3)(5,3)
  \pslineB(0,4)(5,4)
\end{pspicture}\\[2cm]

\psset{unit =1.5cm, linewidth=1.5\pslinewidth}
\begin{pspicture}(5,5)
  \psline(0,1)(5,1)
  \psline[linewidth=1mm](0,2)(5,2)
  \pslineA(0,3)(5,3)
  \pslineB(0,4)(5,4)
\end{pspicture}
\end{document} 

enter image description here

2
  • that has no effect to the line width.
    – user2478
    Apr 15, 2014 at 16:45
  • @Herbert: I modified my answer accordingly.
    – Bernard
    Apr 15, 2014 at 17:07
4

setting the linewidth as a multiple of \pslinewidth sets it as an absolute value, the reason why the \psset{unit=1.5} doesn't change the setting. Compare it with

\newpsobject{pslineA}{psline}{linewidth=0.05, linecolor=green}
\newpsobject{pslineB}{psline}{linewidth=0.2, linecolor=red}

which is a relative linewidth setting which refers to the current units, e.g. 1cm. Then you can say \psset{unit=..} or

\psscalebox{<value>}{%
  \begin{pspicture}(..)(..)
  ...
  \end{pspicture}}

for rescaling the pspicture environment.

1

Best practice suggestions

  1. Lengths in PSTricks accept either relative unit or absolute unit.

    a. Use relative unit for lengths that you might want to scale globally now or in the future. The best candidates for this case are coordinates such as in \psframe(2,3) which is a rectangle of width 2 relative unit and height 3 relative unit where these relative units based on the values given to xunit (=1cm by default) and yunit (=1cm by default).

    b. Use absolute unit for lengths that you might not want to scale globally now or in the future. The best candidate for this case, for example, is line width.

  2. If you just want to scale the lengths of the relative unit, set the base unit via unit, xunit, yunit or runit. For more detailed descriptions for these, see the manual.

  3. If you want to scale everything regardless of their units (either relative or absolute), use \psscalebox. \psscalebox even scales the characters.

  4. By using both unit (or its variants) and \psscalebox, you can adjust your diagrams to have proportional dimensions for both lengths and characters.

See how it works:

\documentclass[preview,border=12pt]{standalone}
\usepackage{pstricks}
\newpsobject{pslineA}{psline}{linewidth=6\pslinewidth, linecolor=green}
\newpsobject{pslineB}{psline}{linewidth=10\pslinewidth, linecolor=red}

\def\foo#1{%
\psset{unit=#1}
\begin{pspicture}(5,5)
  \psline(0,1)(5,1)
  \psline[linewidth=1mm](0,2)(5,2)
  \pslineA(0,3)(5,3)
  \pslineB(0,4)(5,4)
    \rput(2.5,2.5){\color{cyan}$\displaystyle \frac{a}{b}=\frac{c}{d}$}
\end{pspicture}}

\begin{document}
\noindent
\foo{1cm}\\
\psscalebox{3}{\foo{.5}}
\end{document}

enter image description here

1

There is also \psresizebox that was mentioned for a similar question here. This approach rescales everything in the figure including text which can be beneficial if you don't want to to mess up alignment. I use it to include pstricks images that I created with inkscape like this:

\resizebox{\textwidth}{!}{\input{img/pstricksimage}}
2
  • This seems better-suited as a comment. Using \resizebox would change everything, including the size of the text/font used, which seems to be excluded/not referenced in the OP (and can be assumed to remain the same).
    – Werner
    Feb 12, 2021 at 17:53
  • Sorry, didn't have enough rep. to comment other answers. Thanks for the hint that this resizes everything, I'll put that in the answer as well. For me this is indeed a major reason to use this approach as not rescaling the text can mess up alignment of text and lines that I do in inkscape...
    – Hotsndot
    Feb 18, 2021 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .