6

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

  • may be add title/reason for the edit to make it clear and catchy for others – texenthusiast Jul 29 '13 at 21:50
  • @texenthusiast I just made the initial code simpler. :) – Svend Tveskæg Jul 29 '13 at 22:11
6

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.

  • 2
    Great answer. In this, very particular case, pstricks also provides \ncarcbox that creates a similar shape. See p 68 of the pstricks documentation. – Werner Jun 1 '13 at 16:31
  • @Werner thanks, I appreciate the compliment :) I had wondered if there was something a built-in way of doing it- I'll add it to my answer :) – cmhughes Jun 1 '13 at 16:47
  • @SvendTveskæg you're welcome :) – cmhughes Jun 2 '13 at 17:00
3

As Werner already wrote use \ncarcbox:

\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}

\begin{document}

\begin{pspicture}(-4,-4)(4,1)
\pnodes(-3.5,0){A}(3.5,0){B}
\ncarcbox[nodesep=0.2,boxsize=0.2,linearc=0.2,arcangle=90,
     fillstyle=solid,fillcolor=lightgray]{A}{B}
\end{pspicture}

\end{document}

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.