A
在接下来的代码中,我分别显示两个集合和的内容B
,以及确定它们元素之间映射的箭头……
剩下的就是绘制两个集合(即两个椭圆 - 一个在左边,包含ai
和xi
,另一个在右边,包含bi
和yi
)。两个集合的名称A
和B
必须显示在两个椭圆的底部之后。我该怎么做?
\documentclass[a4paper,twoside,10pt]{book}
\usepackage {tikz}
\usetikzlibrary {positioning,graphs,calc,decorations.pathmorphing,shapes,arrows.meta,arrows,shapes.misc}
\usepackage{tikz-cd}
\usepackage{greektex}
\usepackage[american,greek,greek.polytoniko]{babel}
\begin{document}
\begin{center}
\tikzset{every loop/.style={min distance=15mm,looseness=10}}
\begin{tikzpicture}[-latex ,auto ,node distance =0.7cm and 5cm, on grid,semithick ,
state/.style ={circle, draw, color=blue , fill=blue, text=white , minimum width =0.2 cm}]
\node[state] (a1) [label=left:$\alpha_1$]{};
\node[state] (a2) [below =of a1][label=left:$\alpha_2$]{};
\node[state] (a3) [below =of a2][label=left:$\alpha_3$]{};
\node[state] (adots) [below =of a3][label=left:$\vdots$]{};
\node[state] (an) [below =of adots][label=left:$\alpha_n$]{};
\node[state] (b1) [right =of a1][label=right:$\beta_1$]{};
\node[state] (b2) [below =of b1][label=right:$\beta_2$]{};
\node[state] (b3) [below =of b2][label=right:$\beta_3$]{};
\node[state] (bdots) [below =of b3][label=right:$\vdots$]{};
\node[state] (bn) [below =of bdots][label=right:$\beta_n$]{};
\node[state] (x1) [below =of an,yshift=-0.5cm][label=left:$x_1$]{};
\node[state] (x2) [below =of x1][label=left:$x_2$]{};
\node[state] (x3) [below =of x2][label=left:$x_3$]{};
\node[state] (xdots) [below =of x3][label=left:$\vdots$]{};
\node[state] (xn) [below =of xdots][label=left:$x_n$]{};
\node[state] (y1) [below =of bn,yshift=-0.5cm][label=right:$y_1$]{};
\node[state] (y2) [below =of y1][label=right:$y_2$]{};
\node[state] (y3) [below =of y2][label=right:$y_3$]{};
\node[state] (ydots) [below =of y3][label=right:$\vdots$]{};
\node[state] (yn) [below =of ydots][label=right:$y_n$]{};
\path [dashed] (a1) edge (b1); \path [dashed] (b2) edge (a2);
\path [dashed] (b3) edge (a3); \path [dashed] (an) edge (bn);
\path (x1) edge (y1); \path (y2) edge (x2);
\path (y3) edge (x3); \path (xn) edge (yn);
\end{tikzpicture}
\end{center}
\end{document}
答案1
除了 @DungVu 的答案之外,还可以使用库fit
,它允许您创建一个包含所有其他节点的节点。在这里,由于它们是对齐的,您只需从上方和下方包含一个即可。我选择了第二个(a2)
和倒数第二个(xdots)
,以便获得更符合我口味的漂亮椭圆。
\node[fit={(a2)(xdots)},draw, ellipse,minimum width=3cm](left){};
\documentclass[a4paper,twoside,10pt]{book}
\usepackage {tikz}
\usetikzlibrary {positioning,graphs,calc,decorations.pathmorphing,shapes,arrows.meta,arrows,shapes.misc}
\usetikzlibrary{fit}
%\usepackage{tikz-cd}
%\usepackage{greektex}
%\usepackage[american,greek,greek.polytoniko]{babel}
\begin{document}
\begin{center}
\tikzset{every loop/.style={min distance=15mm,looseness=10}}
\begin{tikzpicture}[-latex ,auto ,node distance =0.7cm and 5cm, on grid,semithick ,
state/.style ={circle, draw, color=blue , fill=blue, text=white , minimum width =0.2 cm}]
\node[state] (a1) [label=left:$\alpha_1$]{};
\node[state] (a2) [below =of a1][label=left:$\alpha_2$]{};
\node[state] (a3) [below =of a2][label=left:$\alpha_3$]{};
\node[state] (adots) [below =of a3][label=left:$\vdots$]{};
\node[state] (an) [below =of adots][label=left:$\alpha_n$]{};
\node[state] (x1) [below =of an,yshift=-0.5cm][label=left:$x_1$]{};
\node[state] (x2) [below =of x1][label=left:$x_2$]{};
\node[state] (x3) [below =of x2][label=left:$x_3$]{};
\node[state] (xdots) [below =of x3][label=left:$\vdots$]{};
\node[state] (xn) [below =of xdots][label=left:$x_n$]{};
% left ellipse
\node[fit={(a2)(xdots)},draw, ellipse,minimum width=3cm](left){};
\node[state] (b1) [right =of a1][label=right:$\beta_1$]{};
\node[state] (b2) [below =of b1][label=right:$\beta_2$]{};
\node[state] (b3) [below =of b2][label=right:$\beta_3$]{};
\node[state] (bdots) [below =of b3][label=right:$\vdots$]{};
\node[state] (bn) [below =of bdots][label=right:$\beta_n$]{};
\node[state] (y1) [below =of bn,yshift=-0.5cm][label=right:$y_1$]{};
\node[state] (y2) [below =of y1][label=right:$y_2$]{};
\node[state] (y3) [below =of y2][label=right:$y_3$]{};
\node[state] (ydots) [below =of y3][label=right:$\vdots$]{};
\node[state] (yn) [below =of ydots][label=right:$y_n$]{};
% right ellipse
\node[fit={(b2)(ydots)},draw, ellipse,minimum width=3cm](right){};
\path [dashed] (a1) edge (b1); \path [dashed] (b2) edge (a2);
\path [dashed] (b3) edge (a3); \path [dashed] (an) edge (bn);
\path (x1) edge (y1); \path (y2) edge (x2);
\path (y3) edge (x3); \path (xn) edge (yn);
\end{tikzpicture}
\end{center}
\end{document}
答案2
添加
\draw ($(an)+(0cm,-0.55cm)$) ellipse ({1.5cm} and {4cm});
\draw ($(bn)+(0cm,-0.55cm)$) ellipse ({1.5cm} and {4cm});
% \begin{large}
\draw[color=white] ($(xn)+(0,-1cm)$) node {\color{black}$A$};
\draw[color=white] ($(yn)+(0,-1cm)$) node {\color{black}$B$};
%\end{large}
到你的 Ti钾Z 绘图代码。
如果您发现椭圆不够好,您当然可以更改椭圆绘制命令中的数字。
希望对你有帮助!