我之前没有用过这个venndiagram
包。我尝试阅读手册,但找不到如何让通用集盒适合任意数量的元素的答案。
以下是我目前所掌握的信息:
\documentclass{book}
\usepackage{newfile}
\usepackage{amsmath}
\usepackage{xifthen}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{multirow}
\usepackage{blindtext}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{makecell}
\usepackage{cancel}
\usepackage{tikz}
\usetikzlibrary{tikzmark,shapes.misc}
\usepackage{venndiagram}
\usetikzlibrary{fit}
\usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}
\usepackage{cellspace}
%------------------------------------
%-----------------------------------
\renewcommand\theadfont{\bfseries}
\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
%\setlength\PreviewBorder{5pt}%
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\setlength{\parskip}{5mm}
\begin{document}
\chapter{Sets and Venn Diagrams}
\section{Sets}
A set is a specific group of numbers or items from a list. The items in this set (the list list), are called Elements.\\
Sets can be written in a few different ways - eg the set $A$ can be written as, $A=\{1,8,27,64\}$, $A=\{Cube \: numbers <100\}$ and $A=\{x:x \:is \:a \:cube \:number \:less \:than \:100\}$
\section{Set Notiation}
If we take the natural numbers, $\mathbb{N} \leq10$
\begin{tabular}{|c|c|c|c|}
\hline
Sybmol & Name & Example & Explanation\\
\hline
$\{\}$ & Set & \thead{$A=\{1,3\}$ \\ $B=\{2,3,9\}$ \\ $C=\{3,9\}$} & Collection of objects or items\\
\hline
$\cap$ & intersect & $A \cap B = \{3\}$ & 3 belongs to both sets $A$ and $B$ \\
\hline
$\cup$ & Union & $A \cup B = \{1,2,3,9\}$ & The elements belong to both $A$ and $B$ \\
\hline
$\xi$ & The universal set & $\xi=\ {4,5,6,7,8,10\}$ & All the elements not in the sets \\
\hline
$\subset$ & Proper subset & \thead{$\{1\} \cup A$ \\ $C \cup B$} & A set is contained in another set \\
\hline
$\subseteq$ &Subest & $\thead{B \subseteq A \\ \{1,3\}}$ & A set that is contained in or equal to another set\\
\hline
$\not \subseteq$ & Not a proper subset & $\{1,3\}$ & A set the is not contained in another set \\
\hline
$\supset$ & Superset & $B \supset C$ & Set $B$ includes set $C$\\
\hline
$\epsilon$ & is a member of & $3 \epsilon A$ & $3$ is in the set $A$\\
\hline
$\not\epsilon$ & is not a member of & $4 \not\epsilon A $ & $4$ is not in the set $A $\\
\hline
\end{tabular}
%--------------------------Problem code is here------------------%
my attempt
\begin{venndiagram3sets}[labelOnlyA={1},labelOnlyB= {2},labelOnlyC={}, labelOnlyAB={},labelOnlyAC={},labelOnlyBC= {9},labelABC={3}, labelNotABC={4,5,6,7,8,10}]
\end{venndiagram3sets} %My Attempt
%------------------------------------%
First suggestion
\begin{venndiagram3sets}[
labelOnlyA={1},
labelOnlyB={2},
labelOnlyC={},
labelOnlyAB= {},
labelOnlyAC={},
labelOnlyBC={9},
labelABC={3},
labelNotABC={4,5,6,7,8,10},
showframe=false,
]
\setpostvennhook{
\node[below left] at (venn top right) {\(\mathcal{E}\)};
\node[fit=(venn top right) (venn bottom left) (labelNotABC),draw] {};
}
\end{venndiagram3sets} % second attempt
%--------------------------------------------%
Second suggestion
\fbox{\begin{venndiagram3sets}[showframe=false,labelOnlyA= {1},labelOnlyB={2},labelOnlyC={}, labelOnlyAB= {},labelOnlyAC= {},labelOnlyBC={9},labelABC={3}, labelNotABC={$\xi$ \ {4,5,6,7,8,10\}}]
\end{venndiagram3sets}} %third attempt
%-----------And ends here----------------------------------%
%Diagrams
\section{diagrams}
% Definition of circles
\begin{tabular}{cc}
% Set A and B
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\fill[filled] \secondcircle;
\end{scope}
\draw[outline] \firstcircle node {$A$};
\draw[outline] \secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A \cap B$};
\end{tikzpicture}
&
%Set A or B but not (A and B) also known a A xor B
\begin{tikzpicture}
\draw[filled, even odd rule] \firstcircle node {$A$}
\secondcircle node{$B$};
\node[anchor=south] at (current bounding box.north) {$\overline{A \cap B}$};
\end{tikzpicture}
% Set A or B
\begin{tikzpicture}
\draw[filled] \firstcircle node {$A$}
\secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A \cup B$};
\end{tikzpicture}\\
% Set A but not B
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\draw[filled, even odd rule] \firstcircle node {$A$}
\secondcircle;
\end{scope}
\draw[outline] \firstcircle
\secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A - B$};
\end{tikzpicture}
&
% Set B but not A
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\draw[filled, even odd rule] \firstcircle
\secondcircle node {$B$};
\end{scope}
\draw[outline] \firstcircle node {$A$}
\secondcircle;
\node[anchor=south] at (current bounding box.north) {$B - A$};
\end{tikzpicture}\\
\end{tabular}
\end{document}
答案1
我不确定您想要实现什么,但我认为您想将通用集的标签放在与周围盒子不相交的地方。
这个答案解释了如何使用宏\setpostvennhook
来自定义标签的位置。该包的手册还补充说,维恩图的四个角都有坐标,您可以使用它们来对齐标签。您还可以使用选项vgap
或hgap
增加圆圈和外框之间的边距。
当然,如果标签的内容太长,它最终会“撞上”周围框的右边框……
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{venndiagram}
\begin{document}
\begin{venndiagram3sets}[labelOnlyA={1}, labelOnlyB={2}, labelOnlyC={}, labelOnlyAB= {}, labelOnlyAC={}, labelOnlyBC={9}, labelABC={3}, vgap=.75cm]
\setpostvennhook{
\node[anchor=south west] at (venn bottom left) {$\xi$ \{4,5,6,7,8,10\}};
}
\end{venndiagram3sets}
\end{document}
答案2
您可以使用\setpostvennhook
插入任意 TikZ 代码,以便在构建维恩图后绘制。由于框架的默认大小不考虑标签,因此可以在此处重新绘制并考虑到这一点。具体来说,使用该fit
库可以绘制一个节点,该节点保证包含图表和非 ABC 标签。请注意,您需要选择showframe=false
避免绘制原始通用集框架。
我还做了其他一些更改:
- 不在集合 A、B、C 中的元素不应括在括号中。从技术上讲,书写
\{4,5,6,7,8,10\}
表示外部区域包含一元素是放包含 4,5,6,7,8,10。我猜你想表明的是外部区域本身包含这些数字。 - 为了避免全集符号与元素混淆,我使用了
\setpostvennhook
将其符号放在右上角(我认为这是更标准的位置)。我还使用了\mathcal{E}
而不是\xi
。
\documentclass{book}
%\url{https://tex.stackexchange.com/q/653355/86}
\usepackage{tikz}
\usepackage{venndiagram}
\usetikzlibrary{fit}
\usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}
\begin{document}
\begin{venndiagram3sets}[
labelOnlyA={1},
labelOnlyB={2},
labelOnlyC={},
labelOnlyAB= {},
labelOnlyAC={},
labelOnlyBC={9},
labelABC={3},
labelNotABC={4,5,6,7,8,10},
showframe=false,
]
\setpostvennhook{
\node[below left] at (venn top right) {\(\mathcal{E}\)};
\node[fit=(venn top right) (venn bottom left) (labelNotABC),draw] {};
}
\end{venndiagram3sets}
\end{document}
答案3
除了让venndiagram
包绘制矩形之外,您还可以将其包装到\fbox
\documentclass{book}
\usepackage{makecell}
\usepackage{tikz}
\usepackage{venndiagram}
\renewcommand\theadfont{\bfseries}
\usepackage{cellspace}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\setlength{\parskip}{5mm}
\begin{document}
\fbox{\begin{venndiagram3sets}[showframe=false,labelOnlyA={1},labelOnlyB={2},labelOnlyC={}, labelOnlyAB= {},labelOnlyAC={},labelOnlyBC={9},labelABC={3}, labelNotABC={$\xi$ \{4,5,6,7,8,10\}}]
\end{venndiagram3sets}}
\end{document}