![如何在边缘上贴标签?](https://linux22.com/image/416929/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%BE%B9%E7%BC%98%E4%B8%8A%E8%B4%B4%E6%A0%87%E7%AD%BE%EF%BC%9F.png)
我正在尝试制作一些图表,但我需要在边缘上放置标签,但我尝试将标签放在边缘的中间。有人可以帮助我吗?
\documentclass[border=3pt]{standalone}
\usepackage[upright]{fourier}
\usepackage{tkz-graph}
\usetikzlibrary{arrows}
\begin{document}
\tikzset{Bullet/.style={fill = black, draw, color=#1, outer sep = 2, circle, minimum size = 3pt, scale = 0.75}}
\begin{tikzpicture}
\node[Bullet=black,label=left : {$z_1$}] (z1) at (-6, 2){};
\node[Bullet=black,label=left : {$z_2$}] (z2) at (-6, 0){};
\node[Bullet=black,label=above: {$s_1$}] (s1) at (-4, 4){};
\node[Bullet=black,label=above: {$s_2$}] (s2) at (-4, 2){};
\node[Bullet=black,label=above: {$s_3$}] (s3) at (-4, 0){};
\node[Bullet=black,label=above: {$s_4$}] (s4) at (-4, -2){};
\node[Bullet=black,label=above: {$v_1$}] (v1) at (-1, 6){};
\node[Bullet=black,label=above: {$v_2$}] (v2) at (0, 4){};
\node[Bullet=black,label=above: {$v_3$}] (v3) at (0, 2){};
\node[Bullet=black,label=above: {$v_4$}] (v4) at (0, 0){};
\node[Bullet=black,label=above: {$v_5$}] (v5) at (0, -2){};
\node[Bullet=black,label=above: {$v_6$}] (v6) at (-1, -4){};
\draw (z1)--(s1);
\draw (z1)--(s2);
\draw (z1)--(s3);
\draw (z2)--(s2);
\draw (z2)--(s3);
\draw (z2)--(s4);
\draw (s1)--(v1);
\draw (s1)--(v2);
\draw (s1)--(v4);
\draw (s2)--(v3);
\draw (s2)--(v5);
\draw (s2)--(v6);
\draw (s3)--(v1);
\draw (s3)--(v4);
\draw (s3)--(v6);
\draw (s4)--(v2);
\draw (s4)--(v4);
\draw (s4)--(v3);
答案1
\documentclass[border=3pt]{standalone}
\usepackage[upright]{fourier}
\usepackage{tkz-graph}
%\usetikzlibrary{arrows}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{automata,positioning}
\begin{document}
\tikzset{Bullet/.style={fill = black, draw, color=#1, outer sep = 2, circle, minimum size = 3pt, scale = 0.75}}
\begin{tikzpicture}
\node[Bullet=black,label=left : {$z_1$}] (z1) at (-6, 2){};
\node[Bullet=black,label=left : {$z_2$}] (z2) at (-6, 0){};
\node[Bullet=black,label=above: {$s_1$}] (s1) at (-4, 4){};
\node[Bullet=black,label=above: {$s_2$}] (s2) at (-4, 2){};
\node[Bullet=black,label=above: {$s_3$}] (s3) at (-4, 0){};
\node[Bullet=black,label=above: {$s_4$}] (s4) at (-4, -2){};
\node[Bullet=black,label=above: {$v_1$}] (v1) at (-1, 6){};
\node[Bullet=black,label=above: {$v_2$}] (v2) at (0, 4){};
\node[Bullet=black,label=above: {$v_3$}] (v3) at (0, 2){};
\node[Bullet=black,label=above: {$v_4$}] (v4) at (0, 0){};
\node[Bullet=black,label=above: {$v_5$}] (v5) at (0, -2){};
\node[Bullet=black,label=above: {$v_6$}] (v6) at (-1, -4){};
\draw (z1)--node[left]{C$_4$}(s1);%<-------------add label
\draw (z1)--(s2);
\draw (z1)--(s3);
\draw (z2)--(s2);
\draw (z2)--(s3);
\draw (z2)--(s4);
\draw (s1)--(v1);
\draw (s1)--(v2);
\draw (s1)--(v4);
\draw (s2)--(v3);
\draw (s2)--(v5);
\draw (s2)--(v6);
\draw (s3)--(v1);
\draw (s3)--(v4);
\draw (s3)--(v6);
\draw (s4)--(v2);
\draw (s4)--(v4);
\draw (s4)--(v3);
\end{tikzpicture}
\end{document}
编辑
可以添加其他选项
\draw (z1)--node[left,above, sloped]{C$_4$}(s1);
\draw (z1)--node[left,above, sloped, yshift=-2em]{C$_4$}(s1);
\draw (z1)--node[left,above, sloped]{\scriptsize C$_4$}(s1);
\draw (z1)--node[left,above, sloped, red]{\scriptsize C$_4$}(s1);
编辑
边缘颜色和厚度
\draw[red,ultra thick] (z1)--(s2);