我有一个三圈维恩图
\def\firstcircle{(0,0) circle (2cm)}
\def\secondcircle{(55:2.67cm) circle (2cm)}
\def\thirdcircle{(0:3cm) circle (2cm)}
% Now we can draw the sets:
\begin{tikzpicture}
\draw \firstcircle node[below] {$A$};
\draw \secondcircle node [above] {$B$};
\draw \thirdcircle node [below] {$C$};
\end{tikzpicture}
如何在圆圈重叠的地方添加文本标签?
答案1
一个简单的解决方案是
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{venn circle/.style={draw,circle,minimum width=6cm,fill=#1,opacity=0.4}}
\node [venn circle = red] (A) at (0,0) {$A$};
\node [venn circle = blue] (B) at (60:4cm) {$B$};
\node [venn circle = green] (C) at (0:4cm) {$C$};
\node[left] at (barycentric cs:A=1/2,B=1/2 ) {$A \cap B$};
\node[below] at (barycentric cs:A=1/2,C=1/2 ) {$A \cap C$};
\node[right] at (barycentric cs:B=1/2,C=1/2 ) {$B \cap C$};
\node[below] at (barycentric cs:A=1/3,B=1/3,C=1/3 ){$A \cap B \cap C$};
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage{pst-node}
\SpecialCoor
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt\relax
\PreviewEnvironment{pspicture}
\begin{document}
\begin{pspicture}(-3.25,-3.25)(3.25,3.25)
\def\R{1}
\def\RR{2}
\pnode(\R;30){A}\rput(\RR;30){$A$}
\pnode(\R;150){B}\rput(\RR;150){$B$}
\pnode(\R;270){C}\rput(\RR;270){$C$}
\psset{opacity=0.4}
\def\r{2}
\pscircle*[linecolor=red](A){\r}
\pscircle*[linecolor=green](B){\r}
\pscircle*[linecolor=blue](C){\r}
\def\d{1.5}
\rput(\d;90){$A \cap B$}
\rput(\d;210){$B \cap C$}
\rput(\d;-30){$A \cap C$}
\rput(0,0){$A\cap B\cap C$}
\end{pspicture}
\end{document}
答案3
您可以使用手动放置标签\node at (<x>,<y>) {$A \cap C$};
,但您必须通过反复试验来找到坐标。
更“合适”的方法是使用intersections
库。要使用它,您需要使用唯一名称 ( ) 来命名要相交的路径name path=<name>
,在本例中为圆圈。
name intersections = {of=<firstpath> and <secondpath>}
然后,您可以通过将其作为path
或命令的参数发出来找到交点draw
。
交叉点将作为坐标节点使用,其命名方案为。您现在可以定义两个交叉点之间的路径,并使用在intersection-<number>
中将节点放置在交叉点中间。node [pos=0.5] {<label>}
path
为了标记中心重叠,您可以使用calc
库来指定圆坐标的平均值($0.33*(A)+0.33*(B)+0.33*(C)$)
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}
\def\firstcircle{[name path=firstcircle] (0,0) circle (2cm)}
\def\secondcircle{[name path=secondcircle] (55:2.67cm) circle (2cm)}
\def\thirdcircle{[name path=thirdcircle] (0:3cm) circle (2cm)}
% Now we can draw the sets:
\begin{tikzpicture}
\draw \firstcircle node[below,name=A] {$A$};
\draw \secondcircle node [above,name=B] {$B$};
\draw \thirdcircle node [below,name=C] {$C$};
\path [ name intersections = {of = firstcircle and secondcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$A \cap B$};
\path [ name intersections = {of = secondcircle and thirdcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$B \cap C$};
\path [ name intersections = {of = firstcircle and thirdcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$A \cap C$};
\node at ($0.33*(B)+0.33*(C)+0.33*(A)$) {$A \cap B \cap C$};
\end{tikzpicture}
\end{document}
答案4
对于那些寻找简单东西的人来说,可以考虑使用该 venndiagram
包(依赖于 TikZ):
\documentclass{article}
\usepackage{venndiagram}
\begin{document}
\begin{venndiagram3sets}[labelOnlyAB={$A \cap B$},
labelOnlyAC={$A \cap C$},
labelOnlyBC={$B \cap C$},
labelABC={$A \cap B \cap C$},
radius=3cm,
overlap=2.5cm]
\end{venndiagram3sets}
\end{document}
补充说明:
我确实必须手动调整重叠和半径数字才能使文本更好地契合。
您可以
tikzpicture
使用venndiagram3sets
选项将选项传递给tikzoptions
。虽然您可以改变颜色,但我认为您不能为不同的集合设置不同的颜色。