6

enter image description here

The code I wrote for it is -

\documentclass{article}
\usepackage{amsmath}
\usepackage{pstricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-node,pst-plot}
\begin{document}
\begin{pspicture}(-6,-6)(6,6)
\pscircle(-3,-3){6}
\pscircle(5,-3){6}
\put(-6,-3){$\text{multiples\ of\  2}$}
\put(5.5,-3){$\text{multiples\ of\  3}$}
\put(-1,-3){$\text{multiples of 6}$}
\end{pspicture}
\end{document}

for which the output I am getting is-

enter image description here

You see the problem right?

First I cannot seem to stack the words multiples and of 2 over each other like that. and also, how in the world I shade this specific area. I know how to shade the whole circle i.e. by putting [fillstyle=solid,fillcolor=lightgray] after \pscircle when making the circle.

7

I could only reproduce your output after setting unit to 0.5cm. Anyway, this code produces something close to your desired picture.

\documentclass{article}
\usepackage{pstricks}
\usepackage{amsmath}
\usepackage{auto-pst-pdf}
\begin{document}
\psset{unit=0.5cm}
\begin{pspicture}(-6,-6)(6,6)
\pscircle(-3,-3){6}
\pscircle(5,-3){6}
\rput[c](-4,-3){\begin{tabular}{c}multiples\\ of 2
\end{tabular}}
\rput[c](6,-3){\begin{tabular}{c}
multiples\\ of 3
\end{tabular}
}
\pscustom[fillstyle=solid, fillcolor=lightgray, linestyle=solid]{
    \psarc(-3,-3){6}{-48}{48}
    \psarc(5,-3){6}{132}{228}
    }
\rput[c](1,-3){\begin{tabular}{c}
multiples\\ of 6
\end{tabular}}
\end{pspicture}
\end{document}

enter image description here

I'd also recommend to use the pstricks command \rput instead of \put.

  • what is the difference between \rput and \put? – Bhaskar Vashishth Nov 26 '17 at 2:28
  • @BhaskarVashishth "r" is for "relative". – Przemysław Scherwentke Nov 26 '17 at 2:38
  • @marmot so we have to compute manually -48, 48 and 132 , 228. Is there a trick to get these values automatically? – pzorba75 Nov 26 '17 at 3:40
  • @pzorba75 see Herbert 's post below. Notice that one does not have to compute the angles precisely, though. If you put, say, -60 instead of -48, it also works. – marmot Nov 26 '17 at 7:28
  • @marmot when did you start coming into pstricks territory? – Raaja Jan 22 at 15:21
7

Use clipping:

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

\begin{pspicture}(-6,-3)(6,3)
    \rput(-2.5,0){\shortstack{multiples\\of 2}}
    \rput(2.5,0){\shortstack{multiples\\ of 3}}
    \psclip{\pscircle(-2,0){3}}
        \pscircle[fillstyle=solid, fillcolor=lightgray](2,0){3}
    \endpsclip
    \pscircle(2,0){3}
    \rput(0,0){\shortstack{multiples\\ of 6}}
\end{pspicture}
\end{document}

enter image description here

If you prefer \pscustom, then use

\documentclass{article}
\usepackage{pst-eucl}
\begin{document}

\begin{pspicture}[showgrid](-6,-3)(6,3)
\pstGeonode[PointName=none,PointSymbol=none](-2,0){A}(2,0){B}
\pstInterCC[RadiusA=\pstDistVal{3},RadiusB=\pstDistVal{3}]{A}{}{B}{}{I1}{I2}
\pscustom[fillstyle=solid,fillcolor=red!30]{%
  \pstArcOAB{A}{I2}{I1}
  \pstArcOAB{B}{I1}{I2}
}
\pscircle(A){3}\pscircle(B){3}
\end{pspicture}
\end{document}
4

You can use pst-eucl.

enter image description here

\documentclass[svgnames,dvipsnames]{article}
\usepackage{pstricks,pstricks-add,pst-eucl}
\usepackage{amsmath}
\usepackage{auto-pst-pdf}
\begin{document}

\psset{unit=0.5cm}
\begin{pspicture}[showgrid](-9,-6)(11,6)
\pnode(-3,0){A}
\pnode(5,0){B}
\midAB(A)(B){M}
\def\radA{6}
\def\radB{6}
\pscircle(A){\radA}
\pscircle(B){\radB}
\rput[r](A){\shortstack{multiples\\ of 2}}
\rput[l](B){\shortstack{multiples\\ of 3}}
\pstInterCC[DistCoef=1, RadiusA=\pstDistVal{\radA},DistCoef=1,
                  RadiusB=\pstDistVal{\radB}]{A}{}{B}{}{E}{F}%
\pscustom[fillstyle=solid, fillcolor=lightgray, linestyle=solid]{
    \pstArcOAB{A}{F}{E}
    \pstArcOAB{B}{E}{F}
    }
\rput[c](M){\shortstack{multiples\\ of 6}}
\end{pspicture}
\end{document}

If it is necessary to calculate the angles, this can be done on the postscript-side:

\documentclass[pstricks,border=5mm,x11names,svgnames,dvipsnames]{standalone}
\usepackage{pstricks-add,pst-eucl}
\usepackage{amsmath}
\usepackage{auto-pst-pdf}
\begin{document}

\psset{unit=0.5cm}
\begin{pspicture}[showgrid,saveNodeCoors,NodeCoorPrefix=n](-9,-6)(11,6)
\pnodes(-3,0){A}(5,0){B}
\midAB(A)(B){M}
\def\radA{6}
\def\radB{6}
\pscircle(A){\radA}
\pscircle(B){\radB}
\rput[r](A){\shortstack{multiples\\ of 2}}
\rput[l](B){\shortstack{multiples\\ of 3}}
\pstInterCC[RadiusA=\pstDistVal{\radA},RadiusB=\pstDistVal{\radB}]{A}{}{B}{}{E}{F}%
\pnode(F){Fq}\pnode(E){Eq}
\pscustom[fillstyle=solid,fillcolor=lightgray,linestyle=solid]{
  \psarc(A){\radA}{! nFqy nAy sub nFqx nAx sub atan}{! nEqy nAy sub nEqx nAx sub atan}
  \psarc(B){\radB}{! nEqy nBy sub nEqx nBx sub atan}{! nFqy nBy sub nFqx nBx sub atan}
  }
\rput[c](M){\shortstack{multiples\\ of 6}}
\end{pspicture}
\end{document}
  • @Herbert do you know why the nodes E and F are not working with saveNodeCoors? – user139826 Nov 26 '17 at 7:11
  • \pstArcOAB{A}{E}{F} No need for calculating anything. – user2478 Nov 26 '17 at 7:44
  • pst-eucl handles its own nodes in a different way. The reason why SaveNodeCoors doesn't work. – user2478 Nov 26 '17 at 10:56
  • @Herbert Okay I understand. – user139826 Nov 26 '17 at 12:33
1

Or you could use Metapost, wrapped up here in luamplib, (so compile this with lualatex, or adapt it for GMP or plain MP).

enter image description here

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\def\stack#1{\hbox{\vbox{\let\\\cr\halign{\hss##\hss\cr#1\crcr}}}}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path twos, threes, sixes;

    twos = fullcircle scaled 144 rotated 180 shifted 42 left;
    threes = fullcircle scaled 144           shifted 42 right;
    sixes = buildcycle(twos, threes);

    fill twos   withcolor 3/4[red, white];
    fill threes withcolor 3/4[blue, white];
    fill sixes  withcolor 3/4[1/2 red + 1/2 blue, white];

    draw twos;
    draw threes;

    label("\stack{multiples\\of 2}", center twos shifted 20 left);
    label("\stack{multiples\\of 3}", center threes shifted 20 right);
    label("\stack{multiples\\of 6}", center sixes);

endfig;
\end{mplibcode}
\end{document}

Note

  • The hard work of finding the overlap is done by the buildcycle macro, that finds the overlapping area of one or more paths. There's a small bug (or at least a feature) of this macro that if you use it with only two paths, and if both paths are cyclic (ie closed), then the starting point of one must not be inside the other one.

The built-in path fullcircle starts at 3 o'clock (as it were), so to get buildcycle to work with two fullcircles you need to rotate one or both of them so that these points do not lie inside each other. This is why I used rotated 180 in the definition of the twos path.

1

With the new oefill (odd-even rule) option.

\documentclass[pstricks]{standalone}    
\begin{document}
\begin{pspicture}(-5,-3)(5,3)
\pscustom[fillstyle=oefill,fillcolor=lightgray]{\pscircle(-2,0){3}\pscircle(2,0){3}}
\foreach \x/\y/\t in {-3/0/2,0/0/6,3/0/3}{\rput(\x,\y){\shortstack{multiples\\ of \t}}}
\end{pspicture}
\end{document}

enter image description here

Warning

The red frame is added to show there is a small bug in oefill option. Can you see an extra white space on the left? Also note that oefill sets weirdly "multiples of 2" and "multiples of 3" regions to opaque.

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.