如何绘制一个包含字母或数字的集合?

如何绘制一个包含字母或数字的集合?

我想画一组

在此处输入图片描述

但不知道如何做。我的意思是,如何将对象放入集合中。

答案1

使用邻居回答(+1)作为起点......稍微缩短的代码可以是:

\documentclass[tikz, margin=5mm]{standalone}

\begin{document}
    \begin{tikzpicture}[
ven/.style = {fill=#1, fill opacity=0.5},   % common style for ellipses
every node/.append style ={text opacity=1}  % set text opacity for all nodes
                        ]
\draw[ven=orange]   (0,4)   % coordinate of the ellipse center
                            ellipse (1 and .6) % size of ellipse defined by its radius
                                               node {A}; % node with text in ellipse, 
                                                         % positioned at ellipse center
\draw[ven=cyan]     (3,3.5) ellipse (1 and .6) node {B};
\draw[ven=green]    (0,0)   ellipse (1 and .6) node {C};
\draw[ven=red]      (3,0)   ellipse (1 and .6) node {D};
\draw[ven=yellow]   (4.5,0) ellipse (1 and .6) node {E};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

编辑: 考虑克皮姆在下面的评论中提出建议,上面的代码可以更短。不要绘制椭圆,而是在shapes.gometric`ellipse中定义形状:tikz˙library

\documentclass[tikz, margin=5mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
ven/.style = {ellipse, draw, fill=#1, fill opacity=0.5, text opacity=1,
              minimum width =21mm, minimum height=13mm, },  % common style for ellipses
                        ]
\node[ven=orange]   at (0,3)    {A};
\node[ven=cyan]     at (3,3.5)  {B};
\node[ven=green]    at (0,0)    {C};
\node[ven=red]      at (3,0)    {D};
\node[ven=yellow]   at (4.5,0)  {E};
    \end{tikzpicture}
\end{document}

结果和以前一样:

答案2

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[scale=.5]
        \def\OPAC{.5}
        \draw[fill=orange, fill opacity=\OPAC] (0,0) ellipse (1.5 and 1) node[opacity=1] {A};
        \draw[fill=cyan, fill opacity=\OPAC] (6,-.5) ellipse (1.5 and 1) node[opacity=1] {B};
        \draw[fill=green, fill opacity=\OPAC] (0,-4) ellipse (1.5 and 1) node[opacity=1] {C};
        \draw[fill=red, fill opacity=\OPAC] (5,-4.5) ellipse (1.5 and 1) node[opacity=1] {D};
        \draw[fill=yellow, fill opacity=\OPAC] (7,-4.5) ellipse (1.5 and 1) node[opacity=1] {E};
    \end{tikzpicture}
\end{document}

答案3

只是为了好玩,使用 MetaPost 的同一张图片,与前面的答案具有相同的坐标,并借助 Metafun 格式实现透明度。代码包含在 LuaLaTeX 程序中。

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
    \mplibsetformat{metafun}
\begin{document}
\begin{mplibcode}
path ellipse[];
pair C[]; C1 = (0, 4cm); C2 = cm*(3, 3.5); C3 = origin; C4 = (3cm, 0); C5 = (4.5cm, 0);
color c[]; c1 = .5[red,yellow]; c2 = cyan; c3 = green; c4 = red; c5 = yellow;
beginfig(1);
    for i = 1 upto 5:
        ellipse[i] = fullcircle xscaled 2cm yscaled 1.2cm shifted C[i];
        fill ellipse[i] withcolor c[i] withtransparency ("normal", .5); draw ellipse[i]; 
        label(textext(char(64+i)), C[i]);
    endfor;
endfig;
\end{mplibcode}
\end{document}

在此处输入图片描述

相关内容