[Tex/LaTex] Location of Labels with Crossing Arrows in Commuative Diagrams with tikzcd

commutative-diagramstikz-arrows

I want to add a commutative diagram and started using tilkcd today, but having a trouble with the location of labels attached to an arrow when two arrows cross over with each other.

Here's a commutative diagram in Mac Lane's Cateogory Theory textbook for associativity.

enter image description here

Here's my trial for it.

enter image description here

\usepackage{amsmath, amssymb, graphicx}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[column sep=huge, row sep=huge]
a \arrow[r, "f\circ g\circ h"] \arrow[d, "h"'] \arrow[dr, "g\circ h" very near start] & d \\
b \arrow[r, "g"] \arrow[ur, "f\circ g" very near start] & c \arrow[u, "f"']
\end{tikzcd}

\end{document}

As you can see, the labels attached to the arrows in the middle part look out of place.
I tried 'very near start' and 'inner sep=0ex' but I couldn't make it look better.
Simple problem but any help is much appreciated.

[Edited] Attached the relevant pictures.

Best Answer

One option:

enter image description here

The code:

\documentclass{article}
\usepackage{amsmath, amssymb, graphicx}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[column sep=3cm, row sep=huge]
a \arrow[r, "f\circ (g\circ h) = (f\circ g)\circ h"] \arrow[d, "h"'] \arrow[dr, "g\circ h", pos=0.2,swap] & d \\
b \arrow[r, "g",swap] \arrow[ur, "f\circ g", pos=0.8,swap,crossing over] & c \arrow[u, "f"']
\end{tikzcd}

\end{document}

Remarks

  • You can gain finer control on the position of labels using the pos=<value> option.

  • There's the crossing over option for an arrow that crosses over another.

  • I increased the column sep to 3cm.

Related Question