![维恩图中的阴影部分](https://linux22.com/image/393067/%E7%BB%B4%E6%81%A9%E5%9B%BE%E4%B8%AD%E7%9A%84%E9%98%B4%E5%BD%B1%E9%83%A8%E5%88%86.png)
有人能告诉我如何通过修改代码来遮盖黄色区域吗?提前谢谢大家 :)
\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}
答案1
直截了当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}
当然,可以通过将路径存储在宏中并使用 pgf 键来避免重复并使其更加自动化。然后归结为
\begin{scope}[on background layer]
\pgfkeys{not inside=\pathA,inside/.list={\pathB,\pathC},shade=yellow}
\end{scope}
具有相同的输出。
\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}