4

The title says it all, here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\begin{document}

\def\lcirc2{(-.7,-.5) circle (1cm)}
\def\rcirc2{(.7,-.5) circle (1cm)}
\def\ucirc{(0,.5) circle (1cm)}
\def\rect{(-2.5,-1.8) rectangle (2.5,1.8)}
\begin{tikzpicture}
  \begin{scope}
    \clip \rcirc2;
    \fill[gray] \rcirc2;
    \fill[white] \lcirc2;
    \fill[gray] \ucirc;
  \end{scope}
  \begin{scope}
    \clip \lcirc2;
    \fill[gray] \lcirc2;
    \fill[white] \rcirc2;
  \end{scope}
  \begin{scope}
    \clip \ucirc;
    \fill[gray] \ucirc;
  \end{scope}
  \draw \rect;
  \draw \lcirc2;
  \draw \rcirc2;
  \draw \ucirc;
  \draw (0,2.1) node {$(A\bigtriangleup B)\bigtriangleup C$};
  \draw (0,-.2) node {$X$}; 
\end{tikzpicture}
\end{document}

enter image description here

I need to shade X gray in addition to each circle without the other. Thanks in advance.

2
  • Avoid using numbers in macro names. In any case, I'm not sure what you're trying to achieve. Would it be possible of you to supply a mock-up version (realized externally) of the desired output? – Alenanno Sep 13 '16 at 17:01
  • Please, clarify, what you want to have different. – Heiko Oberdiek Sep 13 '16 at 17:18
5

The "big triangle" notation often means "symmetric difference". Assuming that's correct, this is a nice example of using the even-odd fill rule:

\documentclass[border=0.4in]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
  \def\firstcircle{(90:1.8) circle[radius = 2.4]}
  \def\secondcircle{(210:1.8) circle[radius = 2.4]}
  \def\thirdcircle{(330:1.8) circle[radius = 2.4]}

  \draw (0, 5.5) node {\Large $(A \bigtriangleup B) \bigtriangleup C$};
  \draw[thick] (-5, -3.7) rectangle (5, 4.6);

  \fill[even odd rule, gray] \firstcircle \secondcircle \thirdcircle;
  \draw[thick] \firstcircle \secondcircle \thirdcircle;

  \node[fill = white, shape = circle] (0,0) {$X$};
\end{tikzpicture}
\end{document}

enter image description here

2
  • 2
    You can do \fill[even odd rule, gray, draw=black, thick] and collapse the two TikZ instructions into one. Also, I wouldn't make a white circle around X, but rather display X in white ink. – yo' Sep 13 '16 at 18:18
  • Pedagogy thrives on verbosity, in my experience. – Derek Sep 13 '16 at 18:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.