![在节点中添加权重并改变图中节点的线宽](https://linux22.com/image/446416/%E5%9C%A8%E8%8A%82%E7%82%B9%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%9D%83%E9%87%8D%E5%B9%B6%E6%94%B9%E5%8F%98%E5%9B%BE%E4%B8%AD%E8%8A%82%E7%82%B9%E7%9A%84%E7%BA%BF%E5%AE%BD.png)
考虑以下绘制加权图的 Latex 代码
\documentclass[11pt]{scrartcl}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
\SetUpEdge[lw = 1.5pt,
color = orange,
labelcolor = gray!30,
labelstyle = {draw}]
\GraphInit[vstyle=Normal]
\SetGraphUnit{3}
\tikzset{VertexStyle/.append style={fill}}
\Vertex[x=2,y=1]{S}
\Vertex[x=5,y=2]{A}
\Vertex[x=5,y=-1]{B}
\Vertex[x=7,y=-1]{D}
\Vertex[x=8,y=2]{C}
\Vertex[x=7,y=-3]{E}
\Vertex[x=11,y=1]{G}
\tikzset{EdgeStyle/.style={->}}
\Edge[label=$9$](S)(G)
\Edge[label=$1$](S)(B)
\Edge[label=$2$](S)(A)
\Edge[label=$2$](A)(C)
\Edge[label=$3$](A)(D)
\Edge[label=$2$](B)(D)
\Edge[label=$4$](B)(E)
\Edge[label=$4$](C)(G)
\Edge[label=$4$](D)(G)
\end{tikzpicture}
\end{document}
如何在节点内或节点上方添加权重并改变节点 G 的线宽?
答案1
要更改顶点线宽度,请在其定义之前使用以下命令进行操作:
\renewcommand*{\VertexLineWidth}{2pt}
。
要在顶点周围的任何位置添加节点,请自然地执行此操作:
\path (A) node[above=10pt] {your weight};
。
手册中有很多示例可以帮助您找到改进图表的方法。
\documentclass[11pt]{scrartcl}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
\SetUpEdge[lw = 1.5pt,
color = orange,
labelcolor = gray!30,
labelstyle = {draw}]
\GraphInit[vstyle=Normal]
\SetGraphUnit{3}
\tikzset{VertexStyle/.append style={fill}}
\Vertex[x=2,y=1]{S}
\Vertex[x=5,y=2]{A}
\Vertex[x=4,y=-1]{B}
\Vertex[x=6,y=-1]{D}
\Vertex[x=8,y=2]{C}
\Vertex[x=7,y=-3]{E}
\renewcommand*{\VertexLineWidth}{2pt}
\Vertex[x=11,y=1]{G}
\tikzset{EdgeStyle/.style={->}}
\Edge[label=$9$](S)(G)
\Edge[label=$1$](S)(B)
\Edge[label=$2$](S)(A)
\Edge[label=$2$](A)(C)
\Edge[label=$3$](A)(D)
\Edge[label=$2$](B)(D)
\Edge[label=$4$](B)(E)
\Edge[label=$4$](C)(G)
\Edge[label=$4$](D)(G)
\path (A) node[above=10pt] {your weight};
\end{tikzpicture}
\end{document}