如何在箭头上绘制“箭头标签”

如何在箭头上绘制“箭头标签”

我想绘制这样的图形,箭头上方有“箭头标签”(蓝色边缘和 e_1、e_2 和 e_3 标签): 在此处输入图片描述我总是可以用coordinate它来破解它,但我想知道是否有更简单的方法。

答案1

在此处输入图片描述

\documentclass[tikz,border=10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{simple line}{initial}{%<------https://tex.stackexchange.com/a/216086/197451
  \state{initial}[width=\pgfdecoratedpathlength-1sp]{\pgfmoveto{\pgfpointorigin}}
  \state{final}{\pgflineto{\pgfpointorigin}}
}
\tikzset{
   shift left/.style={decorate,decoration={simple line,raise=#1}},
   shift right/.style={decorate,decoration={simple line,raise=-1*#1}},
}
\begin{document}

\begin{tikzpicture}[]
    \tikzstyle{every node} = [circle, fill=red!30]
    \node (a) at (0, 0) {A};
    \node (b) at +(0: 5) {B};
    \node (c) at +(60: 5) {C};
    \foreach \from / \to in {a/b, b/c, c/a}
        \draw [->] (\from) -- (\to);

        \path[->,blue] (a) edge[shift left=4pt, shorten >=3em, shorten <= 3em] node[fill=none, above]{$e_2$}(b);
  \path[->,orange] (b) edge[shift left=4pt, shorten >=3em, shorten <= 3em] node[fill=none, below]{$e_2$}(a);
\end{tikzpicture}

\end{document}

相关内容