5

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.

1 Answer 1

6

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.

3
  • Thank you very much! I have one question though as a beginner; can I reduce the space between the label and the arrow a bit more? I tried something like \arrow[dr, "g\circ h", pos=0.2, inner sep=0.1ex] but 'pos' and 'inner sep' don't seem to apply at the same time(only pos part).
    – Taxxi
    Commented Jul 18, 2015 at 6:03
  • 1
    @TaxxiDriver You should use outer sep=-2pt or alike. However, you might try \arrow[crossing over]{ur}[near end,description]{f\circ g} or \arrow[crossing over]{ur}[pos=.8,sloped]{f\circ g} as well.
    – LaRiFaRi
    Commented Jul 18, 2015 at 13:17
  • @LaRiFaRi Thank you very much. Now my diagram looks much better!
    – Taxxi
    Commented Jul 18, 2015 at 13:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .