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.

Code

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\begin{figure}
\psset{unit=0.05}
 \begin{pspicture}(120,216)
  \pnodes{P}(0,0)(0,120)(186,120)(216,120)(216,0)(186,0)(186,30)(186,90)
  \pspolygon(P0)(P1)(P3)(P4)
  \pcline[offset=12pt]{|<->|}(P1)(P3)
  \ncput*[nrot=:U]{216}
  \pcline[offset=12pt]{|<->|}(P3)(P4)
  \ncput*[nrot=:U]{120}
  \pspolygon[linestyle=none,fillstyle=vlines](P2)(P3)(P4)(P5)
  \pswedge[linestyle=none,fillstyle=solid,fillcolor=white](P6){30}{270}{90}
  \pswedge[linestyle=none,fillstyle=solid,fillcolor=white](P7){30}{270}{90}
  \psarc(P6){30}{270}{90}
  \psarc(P7){30}{270}{90}
  \psdot(P6)
  \psdot(P7)
 \end{pspicture}
\end{figure}

\end{document}

Output

enter image description here

Question

The code above seems to be the wrong way of creating the figure. I guess \pscustom is the way to go, but I cannot figure out how to use it; how do I produce the figure in the "best" way using PSTricks? (I would very much like to see how it is done and not just get a comment about using this or that.)

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Two frames and two arcs or \pscustom:

\documentclass{article}
\usepackage{pstricks-add}
\begin{document}

\psset{unit=1pt}
\begin{pspicture}(240,140)
\psframe[dimen=middle](216,120)
\psframe[fillstyle=vlines,linestyle=none](186,0)(216,120)
\psarc[fillstyle=solid,fillcolor=white](186,30){30}{-90}{90}
\psarc[fillstyle=solid,fillcolor=white](186,90){30}{-90}{90}
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}
\end{pspicture}

\begin{pspicture}(240,140)
\psframe[dimen=middle](216,120)
\pscustom[fillstyle=vlines,hatchcolor=red]{%
  \psarc(186,30){30}{-90}{90}
  \psarc(186,90){30}{-90}{90}
  \psline(186,120)(216,120)(216,0)
}
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}
\end{pspicture}

\end{document}

enter image description here

Since \psframe draws a closed path (required for proper clipping), it can also be added as the last component in \pscustom if one uses the clipping function:

\documentclass{article}
\usepackage{pstricks-add}% http://tug.org/PSTricks/main.cgi/
\begin{document}

\begin{figure}
\psset{unit=1pt}
\begin{pspicture}(240,140)
\psclip{\psset{linestyle=solid}
  \pscustom{
    \psarc(186,30){30}{-90}{90}
    \psarc(186,90){30}{-90}{90}
    \psframe[dimen=middle](216,120)
  }
}
  \psframe[fillstyle=vlines,linestyle=none](186,0)(216,120)
\endpsclip
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}% Top dimension
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}% Right dimension
\end{pspicture}
\end{figure}

\end{document}

This also works because of the structure and the way \psframe is drawn (counter-clockwise from middle-left.

share|improve this answer
    
Thank you, Herbert! (Any chance I can make you show how to use \pscustom?) –  Svend Tveskæg Apr 3 '13 at 16:49
    
@SvendMortensen: See my edited answer. –  Herbert Apr 3 '13 at 19:30
    
@Herbert Nice! Do you recommend one of the ideas over the other? –  Svend Tveskæg Apr 3 '13 at 19:37
    
@SvendMortensen: that depends ... ;-) if I have enough time then I'd use \pscustom ... –  Herbert Apr 3 '13 at 19:42
    
Okay. Thank you! –  Svend Tveskæg Apr 3 '13 at 19:43
show 2 more comments

I am trying to improve the existing answers.

  • Arrow specifier |<->| should be changed to |<*->|* to make the |-like tips properly aligned.
  • It is better to globally pass dimen=middle to \pscustom rather than locally specifying it to every single command which has dimen=outer by default.
  • As the clipped region is drawn after stroking the clipper path, in general it is necessary to stroke again the clipper path after clipping.

    If you want to understand what I mean, I have added hatchcolor=red,hatchsep=1pt to the clipped \psframe in Werner's edit. Originally Werner's setting is hatchcolor=black so it is unnoticeable but now with the color change, the "defect" is visually obvious as follows.

    enter image description here

    That is why restroking is needed after clipping.

  • Using unit=1pt should be avoided because the navigation grid becomes messy.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\def\Path[#1]{%
  \pscustom[dimen=middle,#1]{
    \psarc(186,30){30}{-90}{90}
    \psarc(186,90){30}{-90}{90}
    \psframe(216,120)
  }\ignorespaces
}

\begin{document}

\psset{unit=1pt,linewidth=3pt}
\begin{pspicture}(240,140)
\psclip{\Path[linestyle=none]}
  \psframe[fillstyle=vlines,hatchcolor=red,hatchsep=1pt,linestyle=none](186,0)(216,120)
\endpsclip
\Path[]
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<*->|*}(0,120)(216,120) \ncput*{216}% Top dimension
\pcline[offset=12pt]{|<*->|*}(216,120)(216,0) \ncput*[nrot=:U]{120}% Right dimension
\end{pspicture}

\end{document}
share|improve this answer
    
Very nice! I will take a look at this and maybe/probably use this version! (I will ping @Herbert to let him know; he might be interested.) –  Svend Tveskæg Apr 6 '13 at 15:12
add comment

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.