我正在创建一个连接节点的图表,并且希望在连接节点的所有边上都有数字。目前它看起来如下:
\begin{figure}[H]
\begin{tikzpicture}
\node[shape=ellipse, draw=black, fill=gray!50] (a) at (7,-4) {a};
\node[shape=ellipse, draw=black, fill=gray!50] (b) at (7,1) {b};
\draw[solid] (b) -- (a) ;
\end{tikzpicture}
\end{figure}
如果我想给a和b之间的线分配一个号码,我该怎么做?
答案1
像这样?关键是使用节点
\draw[solid] (b) --node[pos=xx,position](){3}(a) ;
其中 xx=0~1 且位置= 左、右、上、下
代码
\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,}
\begin{document}
%\begin{figure}[H]
\begin{tikzpicture}
\node[shape=ellipse, draw=black, fill=gray!50] (a) at (7,-4) {a};
\node[shape=ellipse, draw=black, fill=gray!50] (b) at (7,1) {b};
\draw[solid] (b) --node[midway,right](){1} (a) ;
\draw[solid] (b) --node[pos=0.1,left](){2} (a) ;
\draw[solid] (b) --node[pos=0.9,right](){3}(a) ;
\end{tikzpicture}
%\end{figure}
\end{document}