答案1
以下是使用 tikz 的一次尝试:
代码:
\documentclass[border=5mm,tikz]{standalone}
\usepackage{mwe}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw(0,0)--(2,0)--(0,1)--(2,1)--(0,0);
\draw(0,3)--(2,3);
\draw[very thin, double distance=2pt](0.6,2.2)--(1.4,1.6);
\draw[very thin, double distance=2pt](0.6,1.6)--(1.4,2.2);
\foreach \y/\lab in {0/1,1/2,3/h} {
\filldraw(0,\y) circle[radius=2pt]node[left]{$v_{\lab}$};
}
\foreach \y/\lab in {0/n-h+1,3/n,-2/h+1} {
\filldraw(2,\y) circle[radius=2pt]node[right=3mm]{$v_{\lab}$};
}
\filldraw(2,1) circle[radius=2pt];
\node at (0,2) {$\vdots$};
\node at (2,2) {$\vdots$};
\node at (2,-1) {$\vdots$};
\draw[rounded corners] (1.7,-2.3) rectangle (2.3,3.3);
\end{tikzpicture}
\end{document}
答案2
由于该fit
库已被多次提及,因此建议使用它。它需要节点,因此所有黑点都是使用创建的\node
。请注意,通过更改,node distance
您可以修改图形在 y 和 x 方向上的拉伸程度。
十字架是使用不同的技术绘制的,并且相对于它周围的节点,因此修改node distance
也会改变十字架。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{tikzpicture}[
dot/.style={fill,circle,inner sep=0pt,outer sep=0pt,minimum size=3pt,label={[label distance=0.3cm]#1}},
node distance=0.6cm and 1.5cm,]
% draw left column of symbols
% options node name node label
\node [dot={left:$v_h$}] (vh) {};
\node [below=of vh] (vdots1) {$\vdots$};
\node [below=of vdots1,dot={left:$v_2$}] (v2) {};
\node [below=of v2,dot={left:$v_1$}] (v1) {};
% draw right column of symbols
\node [right=of vh,dot={right:$v_n$}] (vn) {};
\node [below=of vn] (vdots2) {$\vdots$};
\node [below=of vdots2,dot={}] (vN) {};
\node [below=of vN,dot={right:$v_{n-h+1}$}] (vnh) {};
\node [below=of vnh] (vdots3) {$\vdots$};
\node [below=of vdots3,dot={right:$v_{h+1}$}] (vh1) {};
% draw lines between dots
\draw (vh) -- (vn);
\draw (v1) -- (vN) -- (v2) -- (vnh) -- (v1);
% draw cross in middle
\foreach \y in {-1,1} {
\draw ($(v2)!0.35!(vn) + (0,\y pt)$) -- ($(vn)!0.35!(v2) + (0,\y pt)$);
\draw ($(vh)!0.35!(vN) + (0,\y pt)$) -- ($(vN)!0.35!(vh) + (0,\y pt)$);
}
% draw rectangle around right column
\node [fit=(vh1)(vn),draw,rounded corners] {};
\end{tikzpicture}
\end{document}