我写了下面的代码
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb,tikz}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
0[fill=blue], 1[fill=red], 2[fill=red]
\node[shape=circle,draw=black,] (0) at (0,0) {$1$};
\node[shape=circle,draw=black] (1) at (5,-1) {$n$};
\node[shape=circle,draw=black] (2) at (4,-2) {$m$};
\node[shape=circle,draw=black] (5) at (5,1) {$3$};
\node[shape=circle,draw=black] (6) at (4,2) {$2$};
\node[shape=circle,draw=black] (7) at (3,3) {$1$};
\draw (0) -- (1);
\draw (0) -- (2);
\draw (0) -- (5);
\draw (0) -- (6);
\draw (0) -- (7);
\end{tikzpicture}
\label{Fig1}
\end{figure}
\end{document}
但我无法生成代替顶点的点。如何获得我想要的输出?有人能帮我吗?
答案1
改编
- 删除了未使用的包
mynode
定义节点的样式- 用于
\foreach
绘制节点和线条 - 画虚线
bend left=20
- 使用极坐标
(<angle>:<distance>)
代码
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
mynode/.style={circle, draw}
]
\node[mynode] (1) at (0,0) {$1$};
\foreach \i in {2, ..., 4} {
\node[mynode] (\i) at ($(1)+({90-\i*15}:40mm)$) {$\i$};
}
\node[mynode] (5) at ($(1)+(-30:40mm)$) {$t$};
\node[mynode] (6) at ($(1)+(-45:40mm)$) {$t+1$};
% solid lines
\foreach \i in {2, ..., 6} {
\draw (1) -- (\i);
}
% dashed & dotted lines
\draw[dashed, shorten <=3mm, shorten >=3mm] (4) to[bend left=20] (5);
\foreach \i in {1, ..., 3} {
\draw[dotted, shorten >=4mm] (1) -- ++({30-\i*15}:40mm);
}
\end{tikzpicture}
\end{document}