如何直接从绘图向边添加标签?

如何直接从绘图向边添加标签?

我正在尝试在由以下代码生成的图表的边缘上添加标签。

有没有办法直接从绘图命令添加这样的标签?

\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}

带有连接线和标签的圆形节点

相关内容