如何畫出一個裡面有字母或數字的集合?

如何畫出一個裡面有字母或數字的集合?

我想畫一組像:

在此輸入影像描述

但不知道該怎麼做。我的意思是,如何將物件放入集合中。

答案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}

在此輸入影像描述

相關內容