4

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.

2 Answers 2

2

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}
0
2
+150

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).

2
  • Thank you. I was aware of the (type of) solution, too. (Note: It is actually \def\hW{16.65 } and not 50/3. Sep 10, 2013 at 14:24
  • Unfortunately, PostScript expressions cannot be used to specify the canvas size. Sep 10, 2013 at 14:29

You must log in to answer this question.

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