我想在 Tikz 中标记一个循环

我想在 Tikz 中标记一个循环
\documentclass[11pt]{article}
\usepackage{tikz-cd}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}



\begin{tikzpicture}
\node (a) at (0,2) {a};
\node (b) at (1,3) {b};
\node (c) at (1,1) {c};
\node (d) at (2,3) {d};
\node (e) at (2,1) {e};

\path[->] (a) edge ["f"] (b);
\path[->] (a) edge ["k"] (c);
\path[->] (b) edge ["g"] (d);
\path[->] (c) edge ["l"] (e);
\path[->] (a) edge [loop left] ["A"] (a);
\end{tikzpicture}

\end{document}

这显示了一个错误,如果我删除循环的标签,它就可以正常工作

答案1

你有两个错误:

  • tikzquotes错过图书馆
  • 选项loop left 必须与标签引号合并。我会使用out=210, in=150, looseness=5,(参见下面的 mwe)来代替它

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,
                quotes% added mised library
                }

\begin{document}
    \begin{tikzpicture}[
every edge quotes/.append style = {font=\footnotesize},% <-- added
                        ]
\node (a) at (0,2) {a};
\node (b) at (1,3) {b};
\node (c) at (1,1) {c};
\node (d) at (2,3) {d};
\node (e) at (2,1) {e};
%
\path[->] % <-- changed to shorter code
    (a) edge ["f"] (b)
    (a) edge ["k"] (c)
    (b) edge ["g"] (d)
    (c) edge ["l"] (e)
    (a) edge [out=210, in=150, looseness=5, "A"] (a);% <-- changed/corrected
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容