我对 TikZ 的了解非常有限。我在我的文档中绘制了这种风格的维恩图:
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\colorlet{circle edge}{red!50}
\colorlet{circle area}{red!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\setlength{\parskip}{5mm}
\begin{scope}
\clip \firstcircle;
\fill[filled] \secondcircle;
\end{scope}
\draw[outline] \firstcircle node {$M_1$};
\draw[outline] \secondcircle node {$M_2$};
\node[anchor=south] at (current bounding box.north) {$M_1 \cap M_2$};
\end{tikzpicture}
\end{figure}
现在,我想画一个补集在维基百科上查看此内容,所以我需要在其周围画一个框并填充一些颜色。操作应该在图片的顶部(如上图所示)。有人知道如何以与第一张图相同的一般风格做到这一点吗?
谢谢你!
答案1
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds, fit}
\begin{document}
\begin{tikzpicture}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\colorlet{circle edge}{red!50}
\colorlet{circle area}{red!20}
\tikzset{
filled/.style = {draw=circle edge, fill=#1!, thick},
outline/.style = {draw=circle edge, thick},
F/.style = {draw, inner sep=7mm, fit=(current bounding box),
node contents={}}
}
\draw[filled=white] \firstcircle node {$M_1$};
\draw[outline] \secondcircle node {$M_2$};
\scoped[on background layer]
\node (a) [F, fill=circle area];
\node[anchor=north] at (current bounding box.north) {A^c=M_1 \setminus M_2};
\end{tikzpicture}
\end{document}