4

How do I add a label to a loop arrow in tikz-cd? I want to label loop arrows as "id". Code snippet:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
M \arrow{r}{\iota_1} \arrow{d}{\iota_2} & G_1 \arrow[shift left=0.8ex]{ld}{g_1} \arrow[loop right]\\
G_2 \arrow{ru}{g_2} \arrow[loop below]
\end{tikzcd}
\end{document}

My goal:

0
5

Try

\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}

\begin{document}
    \begin{tikzcd}
M \ar[r, "\iota_1"] \ar[d, "\iota_2"] 
    & G_1 \ar[ld, shift left, "g_1"] \ar[loop right, "id"]\\
G_2 \ar[ru, shift left, "g_2"] \ar[loop below, "id"]
    \end{tikzcd}
\end{document}

enter image description here

Addendum: To follow suggestion in the @Sebastian comment, here is an example of wee bit effort to prettify above suggested solution:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}

\begin{document}
    \begin{tikzcd}[sep=large,
 every cell/.append style = {inner sep=2pt}, 
every label/.append style = {inner sep=1pt},
every arrow/.append style = {-{Straight Barb[scale=0.8]}},
                    ]
M \ar[r, "\iota_1"] \ar[d, "\iota_2" '] 
    & G_1 \ar[ld, shift left=1.5pt, "g_1"] \ar[looseness=4, out=30, in=330, "id"]\\
G_2 \ar[ru, shift left=1.5pt, "g_2"] \ar[looseness=6, out=300, in=240, "id"]
    \end{tikzcd}
\end{document}

enter image description here

2
  • Just mine it is a humble suggestion. Into the \ar command I suggest to improve the position of labels using the pos=<value> option into \ar[...] because g_1 and g_2 are too far away from the arrows (and I would decrease their character).
    – Sebastiano
    Sep 25 at 21:11
  • 1
    @Sebastiano, well, I didn’t give (now see enough) attention to this aspect of question. This can be improved with defining styles of labels, distances between nodes etc. How to do this, is described in package documentation. Since now is quite late in my time zone, so I will possible prepare a suggestion for better looking diagram example as you suggest.
    – Zarko
    Sep 25 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.