![如何直接从绘图向边添加标签?](https://linux22.com/image/456579/%E5%A6%82%E4%BD%95%E7%9B%B4%E6%8E%A5%E4%BB%8E%E7%BB%98%E5%9B%BE%E5%90%91%E8%BE%B9%E6%B7%BB%E5%8A%A0%E6%A0%87%E7%AD%BE%EF%BC%9F.png)
我正在尝试在由以下代码生成的图表的边缘上添加标签。
有没有办法直接从绘图命令添加这样的标签?
\begin{figure}
\tikzstyle{mynode}=[shape=circle,draw]
\centering
\raisebox{1cm}{\begin{tikzpicture}
\node at (0,0) [mynode] (le) {$e$};
\node at (3,0) [mynode] (lf) {$f$};
\node at (1.5,2) [mynode] (lk) {$k$};
\node at (1.5,0) [mynode] (j) {$j$};
\draw (le) to (j);
\draw (j) to (lf);
\draw (j) to (lk);
\end{tikzpicture}} \end{figure}
答案1
\documentclass[tikz, border=1cm]{standalone}
\tikzset{
mynode/.style={circle, draw}
}
\begin{document}
\begin{tikzpicture}
\node[mynode] at (0,0) (le) {$e$};
\node[mynode] at (3,0) (lf) {$f$};
\node[mynode] at (1.5,2) (lk) {$k$};
\node[mynode] at (1.5,0) (j) {$j$};
\draw (le) --node[fill=white]{a} (j);
\draw (j) --node[above]{b} (lf);
\draw (j) --node[right]{c} (lk);
\end{tikzpicture}
\end{document}