![如何在圆圈中添加数字?](https://linux22.com/image/281558/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%9C%86%E5%9C%88%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%95%B0%E5%AD%97%EF%BC%9F.png)
我想在 Venn 程序中的 3 个位置添加一些数字。但我不知道该怎么做。
\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] {$B$};
\draw \thirdcircle node [text=black,below right] {$C$};
\end{tikzpicture}
\end{document}
答案1
根据您的 tikz 代码,此尝试为两个圆圈定义两个内部名称 B 和 C,并将它们用作参考点,您可以在其中使用多种技巧来放置文本。例如,above, below, left, right= xx cm of reference points
.above right/left, below right/left= xx cm of reference
也可供您使用。您需要\tikzlibrary{positioning}
.
代码:
\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node(B) [text=black,below left] {$B$};
\draw \thirdcircle node (C)[text=black,below right] {$C$};
\node[left= 1cm of B]{1};
\node[right= 1cm of C]{4};
\node[right= 1.2 cm of B]{23};
\end{tikzpicture}
\end{document}
答案2
以下是使用 PSTricks 实现的方法:
\documentclass{article}
\usepackage{pstricks}
\newcommand*\circB{\pscircle(2,2){2}}
\newcommand*\circC{\pscircle(4,2){2}}
\begin{document}
\begin{pspicture}(6,4)
\begin{psclip}{\circB}
\psset{fillstyle = solid, fillcolor = blue!60}
\circC
\end{psclip}
\circB
\circC
\rput(1.1,2){$B$}
\rput(4.9,2){$C$}
\rput(3,2){$1,2,3,4$}
\end{pspicture}
\bigskip
\begin{pspicture}(6,4)
\begin{psclip}{}
\psset{fillstyle = solid, fillcolor = blue!60}
\circB
\psset{fillcolor = white}
\circC
\end{psclip}
\circB
\circC
\rput(1.1,2){$B$}
\rput(4.9,2){$C$}
\rput(3,2){$1,2,3,4$}
\end{pspicture}
\end{document}
答案3
您可以使用该calc
库来计算相对节点位置,例如这里:
\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] (B) {$B$};
\draw \thirdcircle node [text=black,below right] (C) {$C$};
\node at ($(B)!-0.25!(C)$) {1};
\node at ($(B)!0.5!(C)$) {2,3};
\node at ($(B)!1.25!(C)+(0,.5cm)$) {4};
\end{tikzpicture}
\end{document}
答案4
该stackinset
宏允许将文本(或图形)覆盖在现有图像上。插图可以嵌套。插图的位置以图形尺寸指定,相对于底层图像的左/中/右和上/中/下。在本例中,我指定了相对于图像中心的偏移量。
在这种情况下,插图是文本模式,但实际上可以在数学模式、\parbox
es 或任何模式下设置。
\documentclass{letter}
\usepackage[english]{babel}
\usepackage{stackengine}
\usepackage{tikz}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\stackinset{c}{-2.2cm}{c}{-.25cm}{1}{%
\stackinset{c}{}{c}{}{234}{%
\stackinset{c}{2cm}{c}{0.5cm}{5}{%
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] {$B$};
\draw \thirdcircle node [text=black,below right] {$C$};
\end{tikzpicture}%
}}}
\end{document}