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.

Consider the following example:

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\begin{figure}
\def\radius{19.2}
\def\lige{33.3}
\newlength\R \R=\radius\psunit
\newlength\hW \hW=\lige\psunit
\hW=0.5\hW
\centering
 \psset{
   unit=0.2,
   linewidth=1pt
 }
  \begin{pspicture}(-35.5,-18.9)(34.9,18.9)
   \psset{
     linecolor=red
   }
    \psarc( \hW,0){\R}{270}{90}
    \psarc(-\hW,0){\R}{90}{270}
    \psline(-\hW, \R)(\hW, \R)  
    \psline(-\hW,-\R)(\hW,-\R)
   \psset{
     linecolor=black,
     linestyle=dotted
   }
    \psline(-\hW,-\R)(-\hW,\R)
    \psline( \hW,-\R)( \hW,\R)
    \psline(\dimexpr-\hW-\R,0)(\dimexpr\hW+\R,0)
    \rput*(0,0){\lige\,cm}
    \rput*(\dimexpr-\hW-0.5\R,0){\radius\,cm}
    \rput*(\dimexpr \hW+0.5\R,0){\radius\,cm}
    \rput(-\hW,0){\textbf{+}}
    \rput( \hW,0){\textbf{+}}
  \end{pspicture}
\end{figure}

\end{document}

The figure is way too big and changing the unit option apparently has no effect.

How do I fix this?

P.S. The figure used to have the right scale so I have obviously introduced something 'fishy' but I haven't got a clue as to what that is.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I noticed your code contains a logical bug. The canvas size must be

(-\dimexpr\hW+\R,-\radius)(\dimexpr\hW+\R,\radius)

So now my answer has extra value. Why don't accept it? :-)

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\begin{figure}

\centering
 \psset{
   unit=0.2,
   linewidth=1pt
 }
\def\radius{19.2}
\def\lige{33.3}
\newlength\R \R=\radius\psunit
\newlength\hW \hW=\lige\psunit
\hW=0.5\hW
  \begin{pspicture}(-\dimexpr\hW+\R,-\radius)(\dimexpr\hW+\R,\radius)
   \psset{
     linecolor=red
   }
    \psarc( \hW,0){\R}{270}{90}
    \psarc(-\hW,0){\R}{90}{270}
    \psline(-\hW, \R)(\hW, \R)  
    \psline(-\hW,-\R)(\hW,-\R)
   \psset{
     linecolor=black,
     linestyle=dotted
   }
    \psline(-\hW,-\R)(-\hW,\R)
    \psline( \hW,-\R)( \hW,\R)
    \psline(\dimexpr-\hW-\R,0)(\dimexpr\hW+\R,0)
    \rput*(0,0){\lige\,cm}
    \rput*(\dimexpr-\hW-0.5\R,0){\radius\,cm}
    \rput*(\dimexpr \hW+0.5\R,0){\radius\,cm}
    \rput(-\hW,0){\textbf{+}}
    \rput( \hW,0){\textbf{+}}
  \end{pspicture}
\end{figure}

\end{document}
share|improve this answer
    
Note: I did not copy the existing answer! –  Please don't touch Sep 10 '13 at 13:55
1  
Just fine. :) Thank you for the answer too. –  Svend Tveskæg Sep 10 '13 at 13:57
    
I could just as well have chosen your answer. –  Svend Tveskæg Sep 10 '13 at 14:04
    
There you go... accepted. –  Svend Tveskæg Sep 10 '13 at 14:29
    
@SvendTveskæg: Thank you for accepting it, it helped me to increase my reps so I can offer the next bounty for someone. –  Please don't touch Sep 10 '13 at 14:31

Another way is to do the calculations on the Postscript side. This must be enabled with \SpecialCoor, and allows to access the ! notation.

A simple addition then is done like in \pnode(! 1 2 add 1){A}, which is equivalent to \plot(3, 1){A}.

So your example could likewise be written as:

\documentclass[pstricks, border=3pt]{standalone}

\begin{document}
\def\radius{19.2}
\def\R{\radius\space}
\def\lige{33.3}
\def\hW{16.65 }

\SpecialCoor

 \psset{%
   unit=0.2,
   linewidth=1pt
 }%
  \begin{pspicture}(-35.5,-18.9)(34.9,18.9)
   \psset{linecolor=red}
    \psarc(\hW,0){\R}{270}{90}
    \psarc(-\hW,0){\R}{90}{270}
    \psline(-\hW, \R)(\hW, \R)  
    \psline(-\hW,-\R)(\hW,-\R)
   \psset{
     linecolor=black,
     linestyle=dotted
   }
    \psline(-\hW,-\R)(-\hW,\R)
    \psline( \hW,-\R)( \hW,\R)
    \psline(! -\hW \R sub 0)(!\hW \R add 0)
    \rput*(0, 0){\lige\,cm}
    \rput*(! -\hW -0.5 \R mul add 0){\R\,cm}
    \rput*(! \hW 0.5 \R mul add 0){\R\,cm}
    \rput(-\hW,0){\textbf{+}}
    \rput( \hW,0){\textbf{+}}
  \end{pspicture}

\end{document}

Note, that I defined \R as \radius\space, and explicitely left a space after the number in \hW, so one does not always have to write e.g. (!\hW\space \radius\space add 0) in order to get the required white spaces, but with the above definitions it writes as (!\hw \R add).

share|improve this answer
    
Thank you. I was aware of the (type of) solution, too. (Note: It is actually \def\hW{16.65 } and not 50/3. –  Svend Tveskæg Sep 10 '13 at 14:24
    
Unfortunately, PostScript expressions cannot be used to specify the canvas size. –  Please don't touch Sep 10 '13 at 14:29

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.