有没有其他方法来绘制下图?
\begin{picture}(130,80)(-30,10)
\thicklines
\put(50,20){\circle*{4}}
\put(45,10){$w$}
\put(10,70){\circle*{4}}
\put(5,77){$z_1$}
\put(40,70){\circle*{4}}
\put(35,77){$z_2$}
\put(60,70){\circle*{1}}
\put(65,70){\circle*{1}}
\put(70,70){\circle*{1}}
\put(90,70){\circle*{4}}
\put(85,77){$z_d$}
\put(50,20){\line(-4,5){40}}
\put(50,20){\line(-1,5){10}}
\put(50,20){\line(4,5){40}}
\end{picture}
答案1
画成向北生长的树:
\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[
grow = north,
sibling distance = 12mm,
level distance = 21mm,
N/.style = {circle, fill, minimum size=3pt,
inner sep=0pt, outer sep=0pt,
label=#1},
semithick
]
\node[N=below:$w$] {}
child {node[N=$z_4$] {}}
child {node[draw=none] {\dots} edge from parent[draw=none]}
child {node[N=$z_2$] {}}
child {node[N=$z_1$] {}}
;
\end{tikzpicture}
\end{document}
答案2
另一种选择是元帖子,此处已包含在 中luamplib
,因此请使用 进行编译lualatex
(或调整...)。更改N
为您想要的节点数(在合理范围内):
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric N, u, v;
N = 5;
u = 5cm / N;
v = 1cm;
for i=1 upto N:
z[i] = (i-1/2(N+1), 2) xscaled u yscaled v;
if i = N-1:
label("$\cdots$", z[i]);
else:
draw origin -- z[i] withcolor 3/4 red;
dotlabel.top("$z_{" & if i=N: "n" else: decimal i fi & "}$", z[i]);
fi
endfor
dotlabel.bot("$w$", origin);
endfig;
\end{mplibcode}
\end{document}
笔记
您不必声明
numeric
变量,但它有助于确保它们以未定义的方式开始。普通的 Metapost自动将
z$
(其中$
是任何合适的后缀) 定义为一对变量。选项意味着所有标签都由 LaTeX 处理,你可以在将各部分字符串连接在一起后再
luamplib
将它们传递出去进行格式化\mplibtextextlabel{enable}
&
decimal i
生成数字变量的字符串表示形式i
。if ... fi
请注意如何“传统地”或“内联地”使用构造。
答案3
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[mystyle/.style={fill,circle,inner sep=1.5pt,outer sep=0}]
\node[mystyle,label=-90:$w$] (w) at (50pt,20pt) {};
\node[mystyle,label=90:$z_1$] (z1) at (10pt,70pt) {};
\node[mystyle,label=90:$z_2$] (z2) at (35pt,70pt) {};
\node (zd) at (65pt,70pt) {$\cdots$};
\node[mystyle,label=90:$z_4$] (z4) at (85pt,70pt) {};
\draw[thick]\foreach\z in{1,2,4}{(w)--(z\z)};
\end{tikzpicture}
\begin{picture}(130,80)(-30,10)
\thicklines
\put(50,20){\circle*{4}}
\put(45,10){$w$}
\put(10,70){\circle*{4}}
\put(5,77){$z_1$}
\put(40,70){\circle*{4}}
\put(35,77){$z_2$}
\put(60,70){\circle*{1}}
\put(65,70){\circle*{1}}
\put(70,70){\circle*{1}}
\put(90,70){\circle*{4}}
\put(85,77){$z_d$}
\put(50,20){\line(-4,5){40}}
\put(50,20){\line(-1,5){10}}
\put(50,20){\line(4,5){40}}
\end{picture}
\end{document}
答案4
\documentclass{article}
\usepackage{tikzpicture}
\begin{document}
\begin{tikzpicture}[scale=1.1]
\tikzstyle{every node}=[circle, fill=black!,inner sep=0pt, minimum width=4pt]
\node (n_1) at (0,0)[label=below:{$x$}] {};
\node (n_2) at (-1.5,1.5)[label=above:{$y_1$}] {};
\node (n_3) at (-.7,1.8)[label=above:{$y_2$}] {};
\node (n_4) at (.1,1.85)[label=above:{$y_3$}] {};
\node (n_5) at (1.5,1.5)[label=above:{$y_m$}] {};
\foreach \from/\to in
{ n_1/n_5, n_1/n_4, n_1/n_3, n_1/n_2}\draw (\from) -- (\to);
\end{tikzpicture}
\end{document}