我希望集合 P 和 Q 的交集为白色,如附图所示。
我的命令如下:
\documentclass[10pt, a4paper, serif, xcolor = {divpsnames, svgnames}]{beamer}
\usepackage{amsmath, mathtools, mathrsfs, amstext, xfrac}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}
\frametitle{}{}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[fill opacity = .5, text opacity = 1]
\draw[fill = Green!70!white, even odd rule] (5, -2) rectangle (-3.5, 2) (0:2cm) circle [radius = 1];
\draw[fill = Green!70!white, draw = black, even odd rule] (0, 0) circle [radius = 1.5];
\draw[fill = white, draw = black, even odd rule] (0:2cm) circle [radius = 1];
\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\node at (4.7, 1.7) (E) {$E$};
\end{scope}
\end{tikzpicture}
\caption{Representação de $P - Q$.}
\label{fig9}
\end{figure}
\end{frame}
\end{document}
提前致谢!
答案1
简单的方法没有任何魔法,用比背景更深的绿色填充左侧圆圈(集合)的非减法部分,正如您所希望的那样:
\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[Green!35!white, even odd rule]
(5,-2) rectangle (-3.5,2)
(0:2cm) circle[radius = 1];
\fill[Green!60!white] (0,0) circle[radius=1.5];
\filldraw[fill=white, draw=black] (0:2cm) circle [radius=1];
\draw[black] (0, 0) circle [radius=1.5];
\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\node at (4.7, 1.7) (E) {$E$};
\end{tikzpicture}
\end{document}
以下是使用剪切将交叉点填充为白色的另一种方法:
\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[Green!35!white, even odd rule]
(5,-2) rectangle (-3.5,2)
(0:2cm) circle [radius=1];
\filldraw[fill=Green!60!white, draw=black] (0,0) circle[radius=1.5];
\begin{scope}
\clip (0:2cm) circle[radius=1];
\filldraw[fill=white, draw=black] (0,0) circle[radius=1.5];
\end{scope}
\draw[black] (0:2cm) circle [radius=1];
\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\node at (4.7, 1.7) (E) {$E$};
\end{tikzpicture}
\end{document}
有了这个,您可以简单地编辑fill=white
以用您选择的颜色填充两个集合的交集。
答案2
这只是为了好玩,并为您提供一些从各种帖子(当然还有链接)收集的标准技巧。有可能有一个even odd clip
和重用路径。不幸的是,通过实现的“官方”版本use path
并不总是能满足我们的要求,因此还有reuse path
,它允许我们回收之前通过存储在宏中的路径save path
。一般来说,这个工具箱可以相当方便地用于绘制任何维恩图,这些工具也收集在实验钛钾Z 库venn
,但我在这里没有使用它。使用even odd clip
我们可以填充除Q
圆圈之外的所有内容。
\documentclass[10pt, a4paper, serif, xcolor = {divpsnames, svgnames}]{beamer}
\usepackage{tikz}
% based on
% https://tex.stackexchange.com/a/38995/121799
% https://tex.stackexchange.com/a/76216
% https://tex.stackexchange.com/a/59168/194703
% https://tex.stackexchange.com/q/448920/194703
\makeatletter
\tikzset{
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}},
even odd clip/.code={\pgfseteorule}}
\makeatother
\usepackage{amssymb}
\begin{document}
\begin{frame}[t]
\frametitle{Another Venn diagram}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[fill opacity = .5]
\draw[save path=\pathE] (-3.5, -2) rectangle (5, 2);
\draw[save path=\pathQ] (0, 0) circle [radius = 1.5];
\draw[save path=\pathP] (0:2cm) circle [radius = 1];
\clip[even odd clip,reuse path=\pathP] (-3.5, -2) -|(5, 2) -| cycle;
\fill[Green!70!white,use path=\pathE];
\fill[Green!70!white,use path=\pathQ];
\end{scope}
\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\path (5, 2) node[below left](E) {$E$};
\end{tikzpicture}
\caption{Representa\c{c}\~ao de $P - Q$.}
\label{fig9}
\end{figure}
\end{frame}
\end{document}