# How to draw this Venn Diagram using PSTricks?

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-

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.

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}


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. – user121799 Nov 26 '17 at 7:28
• @marmot when did you start coming into pstricks territory? – Raaja Jan 22 at 15:21

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}


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}
\pscustom[fillstyle=solid,fillcolor=red!30]{%
\pstArcOAB{A}{I2}{I1}
\pstArcOAB{B}{I1}{I2}
}
\pscircle(A){3}\pscircle(B){3}
\end{pspicture}
\end{document}


You can use pst-eucl.

\documentclass[svgnames,dvipsnames]{article}
\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}
\rput[r](A){\shortstack{multiples\\ of 2}}
\rput[l](B){\shortstack{multiples\\ of 3}}
\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{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}
\rput[r](A){\shortstack{multiples\\ of 2}}
\rput[l](B){\shortstack{multiples\\ of 3}}
\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

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

\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.

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}


# 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.

• The extra trailing space has been removed by Herbert. – Artificial Stupidity Nov 27 '17 at 16:26