[Tex/LaTex] PSTricks and \pscustom

pstricks

Consider the following example:

Code

% latex filename.tex
% dvips filename.dvi
% ps2pdf filename.ps

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\begin{pspicture}(-3.9,-3.9)(3.8,0.15)
  \pscustom[
    fillstyle = solid,
    fillcolor = lightgray
  ]{%
    \psarc(0,0){3.53}{180}{360}
    \psarc(-3.74,0){0.21}{0}{180}
    \psarc(0,0){3.95}{180}{360}
    \psarc(3.74,0){0.21}{0}{180}
  }
\end{pspicture}

\end{document}

Output

output

Question

How do I make PSTricks fill only the enclosed area (the horizontal line isn't there if you remove \pscustom)?

Best Answer

When using pscustom it's best to have the starting point and ending point match together; indeed, the reason that you are getting the unexpected result is that PSTricks is connecting the first and last points together- in your code, the first and last points are far away from each other, hence the unwanted horizontal line.

I switched the order of a few of your psarc segments, and also changed the direction of some of them from counter clockwise to clockwise using psarcn to keep everything flowing in the same direction.

While debugging, I found it helpful to colour the different segments, and use arrows to show the direction:

enter image description here

Once everything matched, up, adding pscustom back in gave the result as expected:

screenshot

% arara: pdflatex: {shell: true}
% !arara: indent: {overwrite: yes}
\documentclass{standalone}

\usepackage[pdf]{pstricks}
\usepackage{pstricks-add}

\begin{document}

\begin{pspicture}(-4,-4)(4,1)
    \pscustom[fillstyle=solid,fillcolor=lightgray]{%
        \psarc[linecolor=blue]{->}(0,0){3.53}{180}{360}
        \psarcn[linecolor=orange]{->}(3.74,0){0.21}{180}{0}
        \psarcn[linecolor=green]{->}(0,0){3.95}{360}{180}
        \psarcn[linecolor=red]{->}(-3.74,0){0.21}{180}{0}
    }
\end{pspicture}

\end{document}

You'll note that I have left the colours and arrows in the code- just remove them when you're happy with what's going on.

As noted by Werner, in this particular case you might get the same output using ncarcbox, which is detailed on p68 of the documentation.

PS: I've also used the arara tool to help with shell escape.

Related Question