# [Tex/LaTex] Labels in tikzcd

arrowstikz-cd

For some reason the tikzcd documentation that comes with TeXLive says nothing about the following:

1. How do I specify whether or not a label is below/above an arrow?

2. How do I specify the size of diagrams (e.g. if I need a longer arrow to fit a large label)?

3. How can I specify multiple labels (e.g. both above and below) an arrow?

The package documentation contains examples of most of this. Section 1.1 gives examples for placing of labels, Section 2 provides ways to adjust the appearence of the diagram and control spacing. However, the package documentation is easiest to understand in conjunction with the manual for tikz and its underlying language pgf: see http://www.ctan.org/pkg/pgf in particular section 16.8 Placing Nodes on a Line or Curve Explicitly.

By default labels on arrows are to the left of the direction of travel. This my be changed by prefixing the label with [swap], so you can write \arrow{r}{a}[swap]{b} to get an arrow to the right with label a above and b below.

[Code at end.]

Diagrams are set on a grid, so you can't make more space for a single arrow. However, you can open up the grid horizontally and vertically (if necessary with different factors).

Basic tikz options such as for placing labels along the arrow are [pos=0.7] for 0.7 of the way along the length and [near start]/[near end] for near to the beginning or the end.

Labels may be turned with [rotate=90], or some other angle. Doing this you will often need to shift the label with the options xshift or yshift, as in the example above, where one could write

\arrow{d}[anchor=center,rotate=-90,yshift=1ex]{\text{arrow name}}


However, as Qrrbrbrilbel points out it is easier to use sloped together with above or below as in the code below (swap no longer has an effect).

\documentclass{article}

\usepackage{tikz-cd}
\usepackage{mathtools}

\begin{document}
\begin{displaymath}
\begin{tikzcd}
x \arrow{r}{a} \arrow{d}[swap]{b} &y \arrow{d}{d} \\
z \arrow{r}{e}[swap]{c} &w \\
\end{tikzcd}
\end{displaymath}

\begin{displaymath}
\begin{tikzcd}[column sep=6em,row sep=6em]
x \arrow{r}{\text{arrow name}}
\arrow{d} &y \arrow{d}[sloped,above]{\text{arrow
name}} \\
z \arrow{r} &w \\
\end{tikzcd}
\end{displaymath}

\end{document}


If you need a non-grid layout then as in section 3.3 of the manual, you need to resort to basic tikz to place elements.