我正在通过手动创建节点并将其放置在边缘中心来创建边缘标签。有没有更简洁的方法?另外,我希望边缘在标签内不可见。
\begin{figure}
\centering
{
\begin{tikzpicture}[ transform shape]
\newcommand\XA{-3}
\newcommand\YA{0}
\node (x) [circle, draw=black, align=center, minimum size=1cm] at (\XA,\YA) {$V$};
\node (y) [circle, draw=black, align=center, minimum size=1cm ] at (\XA-1.5,\YA-1.5) {$U$};
\node (l1) [thin, draw=black, align=center, minimum width=0.5cm, minimum height=0.5cm] at(\XA-0.75,\YA-0.75) {\Large d};
\path[every node/.style={font=\sffamily\small}]
(x) edge[->] node {} (y);
\end{tikzpicture}
}
\end{figure}
答案1
使用fill=white
。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[transform shape,mylabel/.style={thin, draw=black, align=center, minimum width=0.5cm, minimum height=0.5cm,fill=white,font=\Large}]
\newcommand\XA{-3}
\newcommand\YA{0}
\node (x) [circle, draw=black, align=center, minimum size=1cm] at (\XA,\YA) {$V$};
\node (y) [circle, draw=black, align=center, minimum size=1cm ] at (\XA-1.5,\YA-1.5) {$U$};
\draw[->] (x) -- node[mylabel] {d} (y);
\end{tikzpicture}
\end{figure}
\end{document}
\centering
不接受参数,因此{...}
不需要。另外,edge
它是一个怪物,不要用它来做小事。