我正在使用 tikz 绘制我的图形(完整图形)。我标记了边和顶点,并想在其上添加每个顶点的权重。以下是我所做的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\graph { subgraph K_n [n=3,clockwise,radius=2cm, nodes={circle,draw}] };
\draw (1) -- node[midway, above right] {4} (2);
\draw (1) -- node[midway, above left] {5} (3);
\draw (2) -- node[midway, below] {6} (3);
\end{tikzpicture}
\end{document}
我想要添加的每个顶点的权重为:顶点 1 上为 10,顶点 2 上为 12,顶点 3 上为 14。有办法吗?提前致谢。
答案1
纯粹的tikz
简单:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance =24mm and 12mm,
C/.style = {circle, draw, minimum size=1em}
]
\node (v1) [C, label=10] {1};
\node (v2) [C, label=12, above right=of v1] {2};
\node (v3) [C, label=14, below right=of v2] {3};
%
\draw (v1) to["4"] (v2)
to["6"] (v3)
to["5"] (v1);
\end{tikzpicture}
\end{document}
使用 LuaLaTeX 和 Ti钾Z 库graphs
和循环graphdrawing
:gdlibrary
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,
quotes}
\usegdlibrary {circular}
\begin{document}
\begin{tikzpicture}[
every label/.append style = {font=\small, text=blue}
]
\graph [simple necklace layout,
grow'=down, node sep=22mm,
nodes={draw,circle},
edges={auto, nodes={font=\scriptsize, inner sep=1pt}}
] {
1[label=10] --["4"] 2[label=12] --["6"] 3[label=14] --["5"] 1;
};
\end{tikzpicture}
\end{document}