我需要使用LaTeX绘制加权图,但是我不知道如何将数字放在边缘。数字就像每个边的成本。 可以通过以下方式绘制图形:
\begin{tikzpicture}
\draw
(1, 1) node[circle, black, draw](m){M}
(1, 3) node[circle, black, draw](i){I}
(1, 5) node[circle, black, draw](e){E}
(1, 7) node[circle, black, draw](a){A}
(3, 1) node[circle, black, draw](n){N}
(3, 3) node[circle, black, draw](j){J}
(3, 5) node[circle, black, draw](f){F}
(3, 7) node[circle, black, draw](b){B}
(5, 1) node[circle, black, draw](o){O}
(5, 3) node[circle, black, draw](k){K}
(5, 5) node[circle, black, draw](g){G}
(5, 7) node[circle, black, draw](c){C}
(7, 1) node[circle, black, draw](p){P}
(7, 3) node[circle, black, draw](l){L}
(7, 5) node[circle, black, draw](h){H}
(7, 7) node[circle, black, draw](d){D};
\draw[-] (a) -- (b);
\draw[-] (b) -- (c);
\draw[-] (c) -- (d);
\draw[-] (f) -- (g);
\draw[-] (g) -- (h);
\draw[-] (i) -- (j);
\draw[-] (j) -- (k);
\draw[-] (k) -- (l);
\draw[-] (m) -- (n);
\draw[-] (n) -- (o);
\draw[-] (o) -- (p);
\draw[-] (a) -- (e);
\draw[-] (b) -- (f);
\draw[-] (c) -- (g);
\draw[-] (d) -- (h);
\draw[-] (e) -- (i);
\draw[-] (f) -- (j);
\draw[-] (g) -- (k);
\draw[-] (i) -- (m);
\draw[-] (j) -- (n);
\draw[-] (k) -- (o);
\draw[-] (l) -- (p);
\end{tikzpicture}
答案 0 :(得分:2)
您可以检查Tikz example for many examples of annotated graphs(特别是,有多种方法可以放置边缘标签)。
添加边缘标签的快速方法是在路径上添加节点:
\draw[-] (a) -- node[above] {1} (b);
\begin{tikzpicture}
\draw
(1, 1) node[circle, black, draw](m){M}
(1, 3) node[circle, black, draw](i){I}
(1, 5) node[circle, black, draw](e){E}
(1, 7) node[circle, black, draw](a){A}
(3, 1) node[circle, black, draw](n){N}
(3, 3) node[circle, black, draw](j){J}
(3, 5) node[circle, black, draw](f){F}
(3, 7) node[circle, black, draw](b){B}
(5, 1) node[circle, black, draw](o){O}
(5, 3) node[circle, black, draw](k){K}
(5, 5) node[circle, black, draw](g){G}
(5, 7) node[circle, black, draw](c){C}
(7, 1) node[circle, black, draw](p){P}
(7, 3) node[circle, black, draw](l){L}
(7, 5) node[circle, black, draw](h){H}
(7, 7) node[circle, black, draw](d){D};
\draw[-] (a) -- node[above] {1} (b);
\draw[-] (b) -- node[below] {2} (c);
\draw[-] (c) -- (d);
\draw[-] (f) -- (g);
\draw[-] (g) -- (h);
\draw[-] (i) -- (j);
\draw[-] (j) -- (k);
\draw[-] (k) -- (l);
\draw[-] (m) -- (n);
\draw[-] (n) -- (o);
\draw[-] (o) -- (p);
\draw[-] (a) -- (e);
\draw[-] (b) -- (f);
\draw[-] (c) -- (g);
\draw[-] (d) -- (h);
\draw[-] (e) -- (i);
\draw[-] (f) -- (j);
\draw[-] (g) -- (k);
\draw[-] (i) -- (m);
\draw[-] (j) -- (n);
\draw[-] (k) -- (o);
\draw[-] (l) -- (p);
\end{tikzpicture}