在维恩图中定位条目 - 编辑版本

在维恩图中定位条目 - 编辑版本

此处的代码以维恩图的形式非常美观地显示了三个集合的数字。(集合为ABC,但显示了fFgGhH;它们只是为了方便阅读代码。显示了三个黄色线段、三个蓝色线段和三个黑色线段;它们只是为了方便定位节点。)我想稍微移动一些节点。

在代码中,P是位于图表中心的节点名称;在显示中,2是位于的位置P。我如何将ABC放在黑线段的末端?(C应该在外面circle C。)我如何将78放在黄线段的中点?为什么是3放在其中一个黄线段的中点?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\begin{document}


\begin{tikzpicture}
\draw[overlay,name path=circle A] (-2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle B] (2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle C] (0,-2) circle ({2*sqrt(2)});

\fill[pink!80,fill opacity=0.5,draw=red] (45:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (135:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (-90:2) circle ({2*sqrt(2)});

%The following commands make the following labels: the intersection of circle A and
%circle B that is outside circle C is labeled F, the intersection of circle A and
%circle C that is outside circle B is labeled G, and the intersection of circle B and
%circle C that is outside circle A is labeled H; the intersection of circle A and
%circle B that is inside circle C is labeled f, the intersection of circle A and
%circle C that is inside circle B is labeled g, and the intersection of circle B and
%circle C that is inside circle A is labeled h.
\path[name intersections={of= circle A and circle B, by={F,f}}];
\path[name intersections={of= circle A and circle C, by={G,g}}];
\path[name intersections={of= circle B and circle C, by={h,H}}];
\coordinate[label={$F$}] (point F) at (F);
\coordinate[label={below:$f$}] (point f) at (f);
\coordinate[label={below left:$G$}] (point G) at (G);
\coordinate[label={$g$}] (point g) at (g);
\coordinate[label={below right:$H$}] (point H) at (H);
\coordinate[label={$h$}] (point h) at (h);


%These commands label the point in the middle of the Venn diagram "P." ("P" is not to be displayed.)
%Also, "2" is placed at the location of "P."
\path[line width=0.1pt,name path=Ff] (F) -- (f);
\path[line width=0.1pt,name path=Gg] (G) -- (g);
\path[name intersections={of= Ff and Gg, by=P}];
\node at (P) {2};

%These commands position "5," the number of elements that belong to set $A \cap B$ but not to C,
%"6" the number of elements that belong to set $B \cap C$ but not to A, and "4," the number of
%elements that belong to set $A \cap C$ but not to B.
\path[name path=P-to-H] (P) -- (H);
\path[name intersections={of= P-to-H and circle A, by=P-to-H-and-circle A}];
\path (P-to-H-and-circle A) -- node{6} (H);
\draw[yellow,line width=0.1pt] (P) -- (H);

\path[name path=P-to-G] (P) -- (G);
\path[name intersections={of= P-to-G and circle B, by=P-to-G-and-circle B}];
\path (P-to-G-and-circle B) -- node{4} (G);
\draw[yellow,line width=0.1pt] (P) -- (G);

\path[line width=0.1pt,name path=P-to-F] (P) -- (F);
\path[name intersections={of= P-to-F and circle C, by=P-to-F-and-circle C}];
\path (P-to-F-and-circle C) -- node{5} (F);
\draw[yellow,line width=0.1pt] (P) -- (F);

%These commands position "3," the number of elements that belong to set A but not to $B \cup C$,
%"7," the number of elements that belong to set B but not to $A \cup C$, and "8", the number of
%elements that belong to set C but not to $A \cup B$.
\path[name path=ray-P-h-circle A] (P) -- ($(P)!6cm!0:(h)$);
\path[name intersections={of= ray-P-h-circle A and circle A, by=P-h-circle A-point}];
\path (h) -- node{3} (P-h-circle A-point);
\draw[line width=0.1pt] (P) -- (P-h-circle A-point);

\path[name path=ray-P-g-circle B] (P) -- ($(P)!6cm!0:(g)$);
\path[name intersections={of= ray-P-g-circle B and circle B, by=P-g-circle B-point}];
\path (h) -- node{7} (P-g-circle B-point);
\draw[line width=0.1pt] (P) -- (P-g-circle B-point);

\path[name path=ray-P-f-circle C] (P) -- ($(P)!6cm!0:(f)$);
\path[name intersections={of= ray-P-f-circle C and circle C, by=P-f-circle C-point}];
\path (h) -- node{8} (P-f-circle C-point);
\draw[line width=0.1pt] (P) -- (P-f-circle C-point);

%These commands position the numbers indicating the number of elements in one set that are not
%in the other two sets.

%\path[name intersections={of= Ff and Gg, by=P}];
%\coordinate (T) at ($(F)!0.5!(G)$);
%\draw[line width=0.1pt] (F) -- (G);

%These commands label the sets.
\path[overlay,name path=node A,blue,line width=0.1pt] (P) -- (150:7);
\path[overlay,name path=node B,blue,line width=0.1pt] (P) -- (30:7);
\path[overlay,name path=node C,blue,line width=0.1pt] (P) -- (-90:7);
\path[name intersections={of= node A and circle A, by=alpha}];
\path[name intersections={of= node B and circle B, by=beta}];
\path[name intersections={of= node C and circle C, by=gamma}];
\draw[overlay,blue,line width=0.1pt] (P) -- (alpha);
\draw[overlay,blue,line width=0.1pt] (P) -- (beta);
\draw[overlay,blue,line width=0.1pt] (P) -- (gamma);
\coordinate[label={$A$}] (set A) at (alpha.150);
\coordinate[label={$B$}] (set B) at (beta.30);
\coordinate[label={$C$}] (set C) at (gamma.-90);

\end{tikzpicture}


\end{document}

输出

答案1

如何将 A、B 和 C 放在黑线段的末端?

A一种可能的解决方案是将和的标签更改BC

\coordinate[label={above left:$A$}] (set A) at (alpha.150);
\coordinate[label={above right:$B$}] (set B) at (beta.30);
\coordinate[label={below:$C$}] (set C) at (gamma.-90);

如果这个位置不太符合您的想象,可以使用xshiftyshift参数进行调整(例如\coordinate[label={above left:$A$}, xshift=2cm, yshift=2cm] (set A) at (alpha.150);:)。

我如何将 7 和 8 放在黄线段的中点?为什么 3 放在其中一条黄线段的中点?

在将绘制选项添加到路径后,很明显,7 和 8 不会放置在中点。因此您的命令:

\path (h) -- node{3} (P-h-circle A-point);
\path (h) -- node{7} (P-g-circle B-point);
\path (h) -- node{8} (P-f-circle C-point);

应改为:

\path (h) -- node{3} (P-h-circle A-point);
\path (g) -- node{7} (P-g-circle B-point);
\path (f) -- node{8} (P-f-circle C-point);

因此你的代码变成:

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\begin{document}


\begin{tikzpicture}
\draw[overlay,name path=circle A] (-2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle B] (2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle C] (0,-2) circle ({2*sqrt(2)});

\fill[pink!80,fill opacity=0.5,draw=red] (45:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (135:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (-90:2) circle ({2*sqrt(2)});

%The following commands make the following labels: the intersection of circle A and
%circle B that is outside circle C is labeled F, the intersection of circle A and
%circle C that is outside circle B is labeled G, and the intersection of circle B and
%circle C that is outside circle A is labeled H; the intersection of circle A and
%circle B that is inside circle C is labeled f, the intersection of circle A and
%circle C that is inside circle B is labeled g, and the intersection of circle B and
%circle C that is inside circle A is labeled h.
\path[name intersections={of= circle A and circle B, by={F,f}}];
\path[name intersections={of= circle A and circle C, by={G,g}}];
\path[name intersections={of= circle B and circle C, by={h,H}}];
\coordinate[label={$F$}] (point F) at (F);
\coordinate[label={below:$f$}] (point f) at (f);
\coordinate[label={below left:$G$}] (point G) at (G);
\coordinate[label={$g$}] (point g) at (g);
\coordinate[label={below right:$H$}] (point H) at (H);
\coordinate[label={$h$}] (point h) at (h);


%These commands label the point in the middle of the Venn diagram "P." ("P" is not to be displayed.)
%Also, "2" is placed at the location of "P."
\path[line width=0.1pt,name path=Ff] (F) -- (f);
\path[line width=0.1pt,name path=Gg] (G) -- (g);
\path[name intersections={of= Ff and Gg, by=P}];
\node at (P) {2};

%These commands position "5," the number of elements that belong to set $A \cap B$ but not to C,
%"6" the number of elements that belong to set $B \cap C$ but not to A, and "4," the number of
%elements that belong to set $A \cap C$ but not to B.
\path[name path=P-to-H] (P) -- (H);
\path[name intersections={of= P-to-H and circle A, by=P-to-H-and-circle A}];
\path (P-to-H-and-circle A) -- node{6} (H);
\draw[yellow,line width=0.1pt] (P) -- (H);

\path[name path=P-to-G] (P) -- (G);
\path[name intersections={of= P-to-G and circle B, by=P-to-G-and-circle B}];
\path (P-to-G-and-circle B) -- node{4} (G);
\draw[yellow,line width=0.1pt] (P) -- (G);

\path[line width=0.1pt,name path=P-to-F] (P) -- (F);
\path[name intersections={of= P-to-F and circle C, by=P-to-F-and-circle C}];
\path (P-to-F-and-circle C) -- node{5} (F);
\draw[yellow,line width=0.1pt] (P) -- (F);

%These commands position "3," the number of elements that belong to set A but not to $B \cup C$,
%"7," the number of elements that belong to set B but not to $A \cup C$, and "8", the number of
%elements that belong to set C but not to $A \cup B$.
\path[name path=ray-P-h-circle A] (P) -- ($(P)!6cm!0:(h)$);
\path[name intersections={of= ray-P-h-circle A and circle A, by=P-h-circle A-point}];
\path (h) -- node{3} (P-h-circle A-point);
\draw[line width=0.1pt] (P) -- (P-h-circle A-point);

\path[name path=ray-P-g-circle B] (P) -- ($(P)!6cm!0:(g)$);
\path[name intersections={of= ray-P-g-circle B and circle B, by=P-g-circle B-point}];
\path (g) -- node{7} (P-g-circle B-point);
\draw[line width=0.1pt] (P) -- (P-g-circle B-point);

\path[name path=ray-P-f-circle C] (P) -- ($(P)!6cm!0:(f)$);
\path[name intersections={of= ray-P-f-circle C and circle C, by=P-f-circle C-point}];
\path (f) -- node{8} (P-f-circle C-point);
\draw[line width=0.1pt] (P) -- (P-f-circle C-point);

%These commands position the numbers indicating the number of elements in one set that are not
%in the other two sets.

%\path[name intersections={of= Ff and Gg, by=P}];
%\coordinate (T) at ($(F)!0.5!(G)$);
%\draw[line width=0.1pt] (F) -- (G);

%These commands label the sets.
\path[overlay,name path=node A,blue,line width=0.1pt] (P) -- (150:7);
\path[overlay,name path=node B,blue,line width=0.1pt] (P) -- (30:7);
\path[overlay,name path=node C,blue,line width=0.1pt] (P) -- (-90:7);
\path[name intersections={of= node A and circle A, by=alpha}];
\path[name intersections={of= node B and circle B, by=beta}];
\path[name intersections={of= node C and circle C, by=gamma}];
\draw[overlay,blue,line width=0.1pt] (P) -- (alpha);
\draw[overlay,blue,line width=0.1pt] (P) -- (beta);
\draw[overlay,blue,line width=0.1pt] (P) -- (gamma);
\coordinate[label={above left:$A$}] (set A) at (alpha.150);
\coordinate[label={above right:$B$}] (set B) at (beta.30);
\coordinate[label={below:$C$}] (set C) at (gamma.-90);

\end{tikzpicture}


\end{document}

并产生以下输出: 描述

相关内容