# Closed curve in PSTricks

Consider the following example:

\documentclass{article}

\def\side{%
\psline(-2,2)(-1,2)
\psarc(0,2){1}{180}{0}
\psline(1,2)(2,2)
\psline(-1,1)(0,2)(1,1)
}

\begin{document}

\def\length{60}
\psset{unit=79pt}
\begin{pspicture}(-2,-2)(2.15,2.15)
\multido{\iA=0+90,\iB=-2+1}{4}{%
\psset{offset=12pt,nrot=:U}
\rput{\iA}(0,0){\side}
\ncput*{\length\,cm}
\ncput*{\length\,cm}
}
\end{pspicture}

\end{document}


As can be seen, the curve in not closed. How do I do this (or at least make it look closed; I don't need to fill the inner, so making it look closed is actually enough)?

Note: If someone has a 'simpler' solution than the ones already provided, I would be glad to see it.

-
You can work with \pscustom – Marco Daniel Sep 16 '13 at 11:09

As you don't want to fill the region bounded by segments, then linecap=1 will help here! Note that linecap affects the ends of each line rather than the corner (don't confused it with linejoin). For linejoin see my bonus answer.

\documentclass{article}

\def\side{%
\psline(-2,2)(-1,2)
\psarc(0,2){1}{180}{0}
\psline(1,2)(2,2)
\psline(-1,1)(0,2)(1,1)
}

\begin{document}

\def\length{60}
\psset{unit=79pt,linecap=1}
\begin{pspicture}(-2,-2)(2.15,2.15)
\multido{\iA=0+90,\iB=-2+1}{4}{%
\psset{offset=12pt,nrot=:U}
\rput{\iA}(0,0){\side}
\ncput*{\length\,cm}
\ncput*{\length\,cm}
}
\end{pspicture}

\end{document}


But if you want to change the corner of concatenated lines, then use linejoin.

-
Both nice code and explanation! – Svend Tveskæg Sep 16 '13 at 13:15
I guess inecap=2 is what I want in this case; do you agree? – Svend Tveskæg Sep 16 '13 at 13:37
@SvendTveskæg: Yes. You can also use linecap=2 in your case because it looks good. – kiss my armpit Sep 16 '13 at 13:55
@Herbert Maybe you should change tug.org/PSTricks/Examples/Gallery/exa069.tex to include this refinment. – Svend Tveskæg Sep 20 '13 at 6:21

You must draw a closed curve. A line is an opened curve, you can close it e.g. with \pscustom and \closepath. \pscustom can include also \multido constructs. See the following example for different ways:

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

\begin{document}
\SpecialCoor
\begin{pspicture}(10,2)
\psset{linewidth=10\pslinewidth}

\psline(0,0)(2,0)(2,1)(0,1)(0,0)

\rput(3,0){%
\pscustom{%
\psline(0,0)(2,0)(2,1)(0,1)(0,0)
\closepath
}%
}%

\rput(6.5,0.8){%
\psline(1;-45)(1;45)
\psline(1;45)(1;135)
\psline(1;135)(1;225)
\psline(1;225)(1;315)
}

\rput(9,0.8){%
\pscustom{%
\moveto(1;-45)
\multido{\i=45+90}{4}{%
\psline(1;\i)
}%
\closepath
}%
}%
\end{pspicture}
\end{document}


This gives:

You cannot use \rput inside of \pscustom to position the lines (at the moment don't know the reason for this). So you need to change the \multido part. Here is a part of your document changed to have close curves (maybe there is a more elegant way):

\documentclass{article}

\begin{document}

\def\length{60}
\psset{unit=79pt}
\begin{pspicture}(-2,-2)(2.15,2.15)
\psset{offset=12pt,nrot=:U}
\pscustom{%
\moveto(2,2)
\multido{\iA=-90+-90,\iB=0+-90}{4}{%

@SvendTveskæg I edited my post and added a part of your document to show how it might work. \rput doesn't work properly inside \pscustom. – Christoph Sep 16 '13 at 11:46
Can we have 4 line segments in \pscustom to create a closed curve but each segment has different color? – kiss my armpit Nov 18 '13 at 4:11
@DonutE.Knot No, because \pscustom uses a single path and a single stroke command. – Christoph Nov 18 '13 at 7:21