5

Can someone show me how to shade the yellow region by modifying my code? Thank you in advance guys :)

desired output

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usetikzlibrary{angles}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\draw[thick] (-3,-3.9) rectangle (4,2);
\draw[thick] (0,0) circle (1.5cm);
\draw[thick] (1.5,0) circle (1.5cm);
\draw[thick] (0.75,-1.6) circle (1.5cm);
%
%\scope
%\clip (-3,-2) rectangle (4,2)
%(0,0) circle (1.5cm);
%\fill[gray] (1.5,0) circle (1.5cm);
%\endscope
%
\node [above] at (-3.1,2){$\mathcal{E}$};
\node at (-1.2,1.5) {$A$};
\node at (+2.6,1.5) {$B$};
\node at (+0.75,-3.4) {$C$};
\end{tikzpicture}
\end{document}
10

Straightforward with reverseclip.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds}
% based on https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.south west)rectangle 
(current bounding box.north east)} }} 
\begin{document}
\begin{tikzpicture}
\draw[thick] (-3,-3.9) rectangle (4,2);
\draw[thick] (0,0) circle (1.5cm);
\draw[thick] (1.5,0) circle (1.5cm);
\draw[thick] (0.75,-1.6) circle (1.5cm);
\node [above] at (-3.1,2){$\mathcal{E}$};
\node at (-1.2,1.5) {$A$};
\node at (+2.6,1.5) {$B$};
\node at (+0.75,-3.4) {$C$};
\begin{scope}[on background layer]
\clip (0,0) circle (1.5cm) [reverseclip];
\clip (1.5,0) circle (1.5cm);
\fill[yellow] (0.75,-1.6) circle (1.5cm);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

One can of course avoid repetition and make it a bit more automatic by storing the paths in macros and using pgf keys. Then it boils down to

\begin{scope}[on background layer]
\pgfkeys{not inside=\pathA,inside/.list={\pathB,\pathC},shade=yellow}
\end{scope} 

with the same output.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds}
% based on https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.south west)rectangle 
(current bounding box.north east)} }} 
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\def\PATH{path}
\begin{document}
\pgfkeys{not inside/.code={\clip[use path=#1,reverseclip];},
inside/.code={\clip[use path=#1];},
shade/.code=\fill[#1] (current bounding box.south west)rectangle 
(current bounding box.north east);}
\begin{tikzpicture}
\draw[thick] (-3,-3.9) rectangle (4,2);
\draw[thick,save path=\pathA] (0,0) circle (1.5cm);
\draw[thick,save path=\pathB] (1.5,0) circle (1.5cm);
\draw[thick,save path=\pathC] (0.75,-1.6) circle (1.5cm);
\node [above] at (-3.1,2){$\mathcal{E}$};
\node at (-1.2,1.5) {$A$};
\node at (+2.6,1.5) {$B$};
\node at (+0.75,-3.4) {$C$};
\begin{scope}[on background layer]
\pgfkeys{not inside=\pathA,inside/.list={\pathB,\pathC},shade=yellow}
\end{scope}
\end{tikzpicture}
\end{document}

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.