我目前正在学习如何使用 Tikz 绘制图表。由于我是初学者,我似乎无法弄清楚如何绘制以下图表:
这里令我困惑的是围绕图形顶点的形状以及这些形状下方文本的对齐方式。
这是我目前的代码(它只生成 L0 和 L1):
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2]
\tikzset{vertex/.style={draw, circle, inner sep = 2pt, fill=black}}
\node (v2) at (0,0.5) [vertex] {};
\node (v3) at (.5,1) [vertex] {};
\node (v5) at (.5, .5) [vertex] {};
\node (v6) at (.5, 0) [vertex] {};
\draw (v2) to (v3);
\draw (v2) to (v5);
\draw (v2) to (v6);
\end{tikzpicture}
\end{document}
提前致谢!
答案1
从技术上讲,您提供的代码就是您所需要的。但如果您想画树,您可能需要使用child {}
命令
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{nicefrac,xfrac}
\tikzset{vertex/.style={draw, circle, inner sep = 1pt, fill=black,}}
\begin{document}
\begin{tikzpicture}[grow=0,level 1/.style={sibling distance=3em},
level 2/.style={sibling distance=2em},]
\node[vertex] (z) {}
child { node[vertex] (x){}
child { node[vertex] (y) {} }
child { node[vertex] {} }
}
child { node[vertex] {}
child { node[vertex] (a) {} }
child { node[vertex] (b) {} }
}
child {node[vertex] {}
child { node[vertex] {} }
child { node[vertex] {} }
};
%ellipse
\draw[violet] (0,0) ellipse (0.1cm and 0.5cm);
\draw[violet] (1.5,0) ellipse (0.25cm and 1.5cm);
\draw[violet] (3,0) ellipse (0.5cm and 2cm);
\node[vertex,right of=a, xshift=2cm] (c) {};
\node[vertex,right of=b, xshift=2cm] (d) {};
\draw[dotted] (c) -- (a);
\draw[dotted] (d) -- (b);
\path [bend right] (c) edge (d);
%labels
\node at (0,-3) {$L_{0}$};
\node at (1.5,-3) {$L_{1}$};
\node at (3,-3) {$L_{2}$};
\node at (6,-3) {$L_{\tfrac{K-1}{2}}$};
\end{tikzpicture}
\end{document}