{tikzcd}

Commutative diagrams with TikZ
Version 1.0

May 4, 2021

The general-purpose drawing package TikZ can be used to typeset commutative diagrams and other kindsof mathematical pictures, generating high-quality results. The present package facilitates the creation of suchdiagrams by providing a convenient set of macros and reasonable default settings. Familiarity with TikZ is
helpful but not necessary, since the examples contained here cover the most common situations.
This work may be distributed and/or modified under the conditions of the LATEX Project Public License,
either version 1.3 of this license or (at your option) any later version.

Contents
1 Getting started
1.1 Creating a diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Inserting arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Changing arrow tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Alternative syntax for arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.5 Usage in plain TEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6 Usage in ConTEXt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
2
2
3
4
5
5

2 Controlling the appearance of diagrams
2.1 General options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Global options for arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Absolute placement of arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Phantom arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Fine-tuning the placement of arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6 Three-dimensional diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7 Options for labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5
6
7
8
9
9
10
11

3 Advanced usage11
3.1 Internals of tikzcd and the arrow commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Tweaking to paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Drawing diagrams directly with TikZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Issues with active characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Additional goodies
14
4.1 The asymmetrical rectangle shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2 Reading font parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 Computer Modern arrow tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.4 Glyph arrow tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Index

1

17

Getting started

To load this package in LATEX, type\usepackage{tikz-cd}
or load TikZ and then type\usetikzlibrary{cd}This package is compatible with other TEX formats as well. See §1.5 and §1.6.
1

1.1

Creating a diagram

The basic tool to create a commutative diagram is the following environment.
\begin{tikzcd}[hoptionsi]
henvironment contentsi\end{tikzcd}
The environment contents should describe a matrix, as in LATEX’s familiar {tabular} environment. The
optional argument hoptionsi may be used to modify the appearance of the diagram. Any of the customization
keys described in this manual, as well as those originally provided by TikZ, can be used here. Arrows between
matrix entries can be created with the \arrow command described below.
Everything inside {tikzcd} is typeset in math mode, but you will probably want to use it inside an{equation} environment or \[ …\], so that the diagram is placed on a new line and centered.
It is important to note that dvi viewers will not display diagrams correctly. It is necessary to convert thedvi file to pdf or ps format—or, even better, use a tool that generates pdf files directly, such as pdflatex.

1.2

Inserting arrows

Inside the {tikzcd} environment, the following synonymous commands are provided to produce arrows.
\arrow[hoptionsi]\ar[hoptionsi]
Here, hoptionsi is a comma-separated list of options which can be used to specify the arrow target, addlabels, change arrow tips, and perform additional modifications.
The arrow target can be specified by a direction parameter, which consists of a string of characters r, l,d, u (standing for right, left, down and up). Labels can be placed on an arrow by means of the quotes syntax,
described in detail in the pgf manual [2, §17.10.4]. Notice the use of "\phi" in the example below.
φAB\begin{tikzcd}
A \arrow[rd] \arrow[r, "\phi"] & B \\& C
\end{tikzcd}

C
To further modify the appearance of an arrow, note that hoptionsi may contain any key that can bepassed to TikZ’s \path command. Similarly, a label can receive additional options via the syntax"hlabel texti"hlabel optionsi.
Both hlabel texti and hlabel optionsi need to be enclosed in curly braces if they contain commas.
A

φ

B
ψ

C

η

D

\begin{tikzcd}
A \arrow[r, "\phi"] \arrow[d, red]
& B \arrow[d, "\psi" red] \\C \arrow[r, red, "\eta" blue]& |[blue, rotate=-15]| D\end{tikzcd}

The example above also showcases one of the possible ways to pass special options to a TikZ matrix node.
See the pgf manual [2, §20] for more information.
Arrows can have an arbitrary number of labels, by repeated use of arguments in quotes. The example
below shows how to control the positioning of labels. Notice in particular that an apostrophe as hlabel optioni
causes the label to be placed on the opposite side of the arrow.
A

φ

η
ψ

B

\begin{tikzcd}
A \arrow[r, "\phi" near start, "\psi"', "\eta" near end] & B\end{tikzcd}

We provide two real-life examples.

2

x

T
(x,y)
y

p

X ×Z Y

X

q

f
g

Y

Z

\begin{tikzcd}
T\arrow[drr, bend left, "x"]\arrow[ddr, bend right, "y"]\arrow[dr, dotted, "{(x,y)}" description] & & \\& X \times_Z Y \arrow[r, "p"] \arrow[d, "q"]& X \arrow[d, "f"] \\& Y \arrow[r, "g"]& Z\end{tikzcd}
j1

π1 (U1 )i1

π1 (U1 ∩ U2 )π1 (U1 ) ∗π1 (U1 ∩U2 ) π1 (U2 )'π1 (X)i2

π1 (U2 )j2\begin{tikzcd}[column sep=tiny]& \pi_1(U_1) \ar[dr] \ar[drr, "j_1", bend left=20]&&[1.5em] \\\pi_1(U_1\cap U_2) \ar[ur, "i_1"] \ar[dr, "i_2"']&& \pi_1(U_1) \ast_{ \pi_1(U_1\cap U_2)} \pi_1(U_2) \ar[r, dashed, "\simeq"]& \pi_1(X) \\& \pi_1(U_2) \ar[ur]\ar[urr, "j_2"', bend right=20]&&\end{tikzcd}

1.3

Changing arrow tips

A set of \arrow options is provided to create different kinds of arrows. Some of these options have a short
descriptive name, such as hook, and others are named after TEX arrow-producing commands (without a “\”),like dashrightarrow.
XX̄
Y\begin{tikzcd}
X \arrow[r, hook] \arrow[dr, dashrightarrow]& \bar{X} \arrow[d]\\& Y\end{tikzcd}

The following list shows all available arrow types (each of them is a style key located in /tikz/commutative
diagrams).
Basic arrows
to headrightarrowleftarrowleftrightarrow
Rightarrow
Leftarrow
Leftrightarrow

Arrows from bar
yieldsyieldsyieldsyieldsyieldsyieldsyieldsmaps tomapstomapsfrom
MapstoMapsfrom3

yieldsyieldsyieldsyieldsyieldsArrows with hook

Dashed arrows
yieldsyieldsyieldsyieldshookhook'
hookrightarrow
hookleftarrow

dasheddashrightarrowdashleftarrow
Squiggly arrows

Arrows with tailsquiggly
rightsquigarrowleftsquigarrowleftrightsquigarrow

yieldsyieldsyieldstailrightarrowtail
leftarrowtail

Two-headed arrows

no headno taildash
equal

Harpoons
harpoonharpoon'rightharpoonup
rightharpoondown
leftharpoonup
leftharpoondown

yieldsyieldsyieldsyieldsNon-arrows

yieldsyieldsyieldstwo heads
twoheadrightarrow
twoheadleftarrow

yieldsyieldsyieldsyieldsyieldsyieldsyieldsyieldsyieldsyieldsyieldsyieldsyields

A gray cross ( ) in the samples above indicates that the corresponding tip is kept unchanged. This allows
several arrow styles to be superimposed.
A

1.4

B

\begin{tikzcd}
A \arrow[r, tail, two heads, dashed] & B\end{tikzcd}

Alternative syntax for arrows

The following forms of the arrow command were used before the appearance of the quotes syntax for labels,
and now may seem somewhat convoluted. They are nonetheless still available for backwards compatibility.
\arrow[hoptionsi]{hdirectioni}hlabelsi
Here, hdirectioni is a string containing the characters r, l, d, u and is used to determine the arrow target.
Alternatively, you can specify an explicit matrix cell by replacing hdirectioni with something of the form hrownumberi-hcolumn numberi, or the name of a node. The trailing hlabelsi can be the empty string or of theform[hlabel optionsi]{hlabel texti}hmore labelsi.
The equivalent command \ar can also be used in this form. Here is an example.
A

φ ψ

B
ξ

C

η

D

\begin{tikzcd}
A \arrow{d} \arrow{r}[near start]{\phi}[near end]{\psi}& B \arrow[red]{d}{\xi} \\C \arrow[red]{r}[blue]{\eta}& D\end{tikzcd}

There are further shortened forms:\rar[hoptionsi]hlabelsi\lar[hoptionsi]hlabelsi\dar[hoptionsi]hlabelsi\uar[hoptionsi]hlabelsi\drar[hoptionsi]hlabelsi
4\urar[hoptionsi]hlabelsi\dlar[hoptionsi]hlabelsi\ular[hoptionsi]hlabelsi
The first one is equivalent to\arrow[hoptionsi]{r}hlabelsi
and the other ones work analogously.

1.5

Usage in plain TEX

To use this package in plain TEX, load TikZ and the cd library by saying\input tikz.tex\usetikzlibrary{cd}
The {tikzcd} environment should then be replaced by the following:\tikzcd[hoptionsi]
henvironment contentsi\endtikzcd
All other functions of this library work as described in this manual without change.

1.6

Usage in ConTEXt

To use this package in ConTEXt, load TikZ and then the cd library by saying\usemodule[tikz]\usetikzlibrary[cd]The {tikzcd} environment should then be replaced by the following:\starttikzcd[hoptionsi]
henvironment contentsi\stoptikzcd
Moreover, you may replace the column and row separators &, \\ by their ConTEXt analogues \NC, \NR.
However, you should use \NC only between cells, and not before the first column or after the last column, as
in usual ConTEXt tables. Similarly, \NR should be used only between rows.
All other functions of this library work as described in this manual without change.

2

Controlling the appearance of diagrams

This section describes a number of customization keys defined by this package. All keys are located in thepath /tikz/commutative diagrams. Options passed to {tikzcd} or \arrow are searched for in that path,and, if not found there, in /tikz. To set options globally, it is convenient to use the following command.
\tikzcdset{hoptionsi}
Executes hoptionsi in the path /tikz/commutative diagrams.
Besides the keys described in this manual, numerous TikZ parameters can affect the appearance of adiagram. However, only a few of them (namely those appearing in every diagram, every cell, every arrow,and every label below) are reinitialized when {tikzcd} is called. This means that modifying a certain
TikZ parameter globally may or may not affect the output of {tikzcd}.
We also point out that besides the options and styles provided by this package, several keys defined by
TikZ are useful for arrows. Some examples are dashed, dotted, and its relatives, line width=hdimensioni,
color=hcolori, bend right, bend left, in=hanglei, out=hanglei, loop, etc. See the pgf manual [2, §15.3.1
and §74]. Likewise, TikZ provides several keys that are useful for labels, such as above, below, left,right, swap (which makes the label be placed on the right side of the arrow, relative to its direction),sloped, pos=hfractioni, near start, near end, inner sep=hdimensioni, font=hfont commandi, text
width=hdimensioni, etc. See the pgf manual [2, §17, esp. §17.8].
5

2.1

General options(style, no value)/tikz/commutative diagrams/every diagram

This style is applied to every {tikzcd} environment. Initially, it contains the following:
row sep=normal,
column sep=normal,/tikz/baseline=0pt
The baseline=0pt setting is used to make equation numbers be placed correctly (as an exception, one-row
diagrams are anchored at their matrix base, which is exactly what you want).
(no default)/tikz/commutative diagrams/diagrams=hoptionsiThis key appends hoptionsi to the style every diagram.

(style, no value)/tikz/commutative diagrams/every matrix

This style is applied to the TikZ matrix created internally by {tikzcd}. Initially, it contains thefollowing:/tikz/inner sep=0pt(style, no value)/tikz/commutative diagrams/every cellThis style is applied to every TikZ matrix cell created by {tikzcd}. Initially, it contains the following:/tikz/shape=asymmetrical rectangle,/tikz/inner xsep=1ex,/tikz/inner ysep=0.85ex
The asymmetrical rectangle shape is described in §4.1. The inner xsep, inner ysep options determine the spacing between a diagram entry and any arrows reaching it.
(no default)/tikz/commutative diagrams/cells=hoptionsiThis key appends hoptionsi to the style every cell.

(no default)/tikz/commutative diagrams/row sep=hsizei
This key acts as a frontend to TikZ’s /tikz/row sep key. If the key/tikz/commutative diagrams/row sep/hsizei

stores a hvaluei, then it is read and /tikz/row sep=hvaluei is set. If the key above is not initialized,then hsizei is presumed to be a dimension, and /tikz/row sep=hsizei is set.
The initially available sizes, and their values, are the following:tiny
small scriptsize normal
0.45 em 0.9 em
1.35 em
1.8 emlarge
2.7 emhuge
3.6 emNotice that setting, say, row sep=1cm globally with \tikzcdset will have no effect, since the row sep
option is re-set at the beginning of each diagram. To make all diagrams have row sep equal to 1 cm, you can
modify the meaning of normal by saying\tikzcdset{row sep/normal=1cm}.
You can also create new sizes, but note that pgf requires new keys to be initialized explicitly. For example,
to create a size my size, meaning 1 ex, you should use\tikzcdset{row sep/my size/.initial=1ex}.
(no default)/tikz/commutative diagrams/column sep=hsizei

This works analogously to the row sep key above. The sizes available initially are the following:tiny
small scriptsize normal large
huge
0.6 em 1.2 em
1.8 em2.4 em 3.6 em 4.8 em

6

(no default)/tikz/commutative diagrams/sep=hsizei
This key sets row sep=hsizei, column sep=hsizei.

In the examples below, the triangular diagrams would look too wide or too tall if the column or row
separation were not set appropriately.
A
B

C

B
A
C

\begin{tikzcd}[column sep=small]& A \arrow[dl] \arrow[dr] & \\B \arrow{rr} && C\end{tikzcd}\begin{tikzcd}[row sep=tiny]& B \arrow[dd] \\A \arrow[ur] \arrow[dr] &\\& C\end{tikzcd}

Section 20.3.2 of the pgf manual [2] contains further details on the spacing of matrix cells.
(style, no value)/tikz/commutative diagrams/cramped

By default, a generous amount of white space is added around diagram cells, which is appropriate forlarge, displayed diagrams. The present style removes some of this extra white space, and is intended forsmaller diagrams that should blend with the surrounding text, or very wide material that wouldn’t fit
the page otherwise.
The picture below shows the (somewhat subtle) difference between the cramped and the non-cramped
styles.
This A
B is a regular diagram.
This A
B is a cramped diagram.
This A → B is just a formula.
This \begin{tikzcd} A \arrow[r] & B \end{tikzcd} is a regular diagram.\\This \begin{tikzcd}[cramped, sep=small] A \arrow[r] & B \end{tikzcd} is a cramped diagram.\\This $A \to B$ is just a formula.

Keep in mind that while there are some legitimate uses for {tikzcd} diagrams on inline formulas, standard
LATEX constructs such as \overset and \xrigthtarrow are often sufficient and should be preferred.
/tikz/commutative diagrams/math mode=hbooleani(default true)

This key determines whether or not the contents of a diagram are typeset in math mode. If set globallyor diagram-wise, it affects both the diagram entries and arrow labels. If used with \arrow, it affects
only its labels.
/tikz/commutative diagrams/background color=hcolori(no default, initially white)This key stores the name of a color, and is read by styles that fill the background, such as description
and crossing over. It does not cause the background of diagrams to be filled.

2.2

Global options for arrows(style, no value)/tikz/commutative diagrams/every arrow
This style is applied to every \arrow. Initially, it contains the following:/tikz/draw,/tikz/line width=rule_thickness,rightarrow(no default)/tikz/commutative diagrams/arrows=hoptionsiThis key appends hoptionsi to the style every arrow.
7

/tikz/commutative diagrams/arrow style=hstylei(no default)This key determines which collection of arrow tips is used by the arrow tip selection styles listed in §1.3.
The initial setting is suitable for documents using the Computer Modern font at any size. The available
choices for hstylei are:
Latin Modern A small variant of the initial settings, intended for documents using the Latin Modern
font at any size.
math font This setting uses the Glyph meta arrow tip described in §4.4.
tikz This setting uses the arrow tips defined in TikZ’s arrows.meta library. It honors the option/tikz/>.
This key is usually invoked in the document preamble, and should be set only once.
If you are using a font different from Computer Modern or Latin Modern, you may find the best results byselecting the math font style. As detailed in §4.4, this is not guaranteed to work perfectly with all fonts, but
gives good results in many cases. If the math font style gives unsatisfactory results, you can try selecting thetikz style, and setting /tikz/> to the value that best matches your font (among those shown in [2, §16.5]).
A

B
D% in preamble\tikzcdset{
arrow style=tikz,
diagrams={>={Straight Barb[scale=0.8]}}}% in document body\begin{tikzcd}
A \arrow[r, tail] \arrow[rd] & B \arrow[d, two heads]\\& D\end{tikzcd}

2.3

Absolute placement of arrows

The usual behavior of \arrow is to produce an arrow starting at the diagram entry where the commandappears, and ending at an entry whose location is specified relative to that. The following keys override thisbehavior, allowing source and target to be selected explicitly.
(no default)/tikz/commutative diagrams/from=hargumenti

If hargumenti is of the form hrow numberi-hcolumn numberi, or if it is a string of characters r, l, d, u,
this key sets the arrow source to be the corresponding cell in the diagram matrix. Otherwise, it assumes
the argument is the name of a node and sets the arrow source to hargumenti.
(no default)/tikz/commutative diagrams/to=hargumenti
Similar to from, but refers to the arrow target.

Recall that it is possible to give a specific entry of a TikZ matrix a name by using the |[hoptionsi]|
syntax, as done for entry C in the example below. You must be careful not to create nodes whose namecontains only the characters l, r, u, d if you want to refer to them using from or to. The following illustrates
several different uses of these keys.
A

B

C

D

\begin{tikzcd}
A \arrow[to=Z, red] \arrow[to=2-2, blue]& B \\|[alias=Z]| C& D\arrow[from=ul, to=1-2, purple]\end{tikzcd}

In the next examples, empty labels are used to create nodes for later reference. The draw=red option isused to show where these empty nodes are located, but of course you want to remove that when using thistechnique.
A

B
ψ

C

\begin{tikzcd}[column sep=scriptsize]
A \arrow[dr] \arrow[rr, ""{name=U, below, draw=red}]{}& & B \arrow[dl] \\& C \arrow[Rightarrow, from=U, "\psi"]\end{tikzcd}

8

A

2.4

B

\begin{tikzcd}
A \arrow[r, bend left=50, ""{name=U, below, draw=red}]\arrow[r, bend right=50, ""{name=D, draw=red}]& B\arrow[Rightarrow, from=U, to=D]\end{tikzcd}

Phantom arrows

Sometimes it is necessary to insert a symbol outside the grid subjacent to the diagram. The easiest way toachieve this is as a label to an invisible arrow.
(style, no value)/tikz/commutative diagrams/phantom

Creates an invisible arrow. Labels to this arrow are not invisible. They will be anchored at their centerand typeset in full size (i.e., with \textstyle). To get smaller labels, as in ordinary arrows, use the\scriptstyle command.
In the picture below, the arrow containing the phantom option goes from A to D, and the \ulcorner
symbol (p) is inserted closer to the starting point A.
A

B
p

C

2.5

D

\begin{tikzcd}
A \arrow[r] \arrow[d] \arrow[dr, phantom, "\ulcorner", very near start]& B \arrow[d] \\C \arrow[r]& D\end{tikzcd}

Fine-tuning the placement of arrows/tikz/commutative diagrams/shift left=hdimensioni(default 0.56ex)

Shifts arrows by hdimensioni to the left, relative to the arrow direction. A dimensionless argument
causes that multiple of the default value to be used.
/tikz/commutative diagrams/shift right=hdimensioni(default 1)

A shortcut to shift left=-hdimensioni.
A

BC\begin{tikzcd}
A \arrow[r, red, shift left=1.5ex] \arrow[r]\arrow[dr, blue, shift right=1.5ex] \arrow[dr]& B \arrow[d, purple, shift left=1.5ex] \arrow[d]\\& C\end{tikzcd}

The default values of shift left and shift right are appropriate for a pair of parallel arrows, anddimensionless arguments are useful to create sets of multiple parallel arrows.
A

B

C

···

\begin{tikzcd}
A \arrow[r]& B \arrow[r, shift left]\arrow[r, shift right]& C \arrow[r]\arrow[r, shift left=2]\arrow[r, shift right=2]& \cdots\end{tikzcd}/tikz/commutative diagrams/shift={hcoordinatei}(no default)

Shifts arrows by hcoordinatei.
/tikz/commutative diagrams/xshift=hdimensioni
Shifts arrows right by hdimensioni.
9(no default)

/tikz/commutative diagrams/yshift=hdimensioni(no default)

Shifts arrows up by hdimensioni.
A

BC\begin{tikzcd}
A \arrow[r, yshift=0.7ex] \arrow[r, yshift=-0.7ex]& B \arrow[d, xshift=0.7ex] \arrow[d, xshift=-0.7ex] \\& C\end{tikzcd}/tikz/commutative diagrams/start anchor={[hcoordinate transformationsi]hanchori}(no default)This key specifies at which anchor of the source node the arrow should start. Optionally, additional
coordinate transformations can be supplied. An empty hanchori argument causes no anchor to be
specified, which is the usual behavior.
/tikz/commutative diagrams/end anchor={[hcoordinate transformationsi]hanchori}(no default)This key works analogously, but refers to the target node of the arrow.
See the picture on §4.1 for some of the possible values for hanchori.
AB\begin{tikzcd}[cells={nodes={draw=gray}}]
A \arrow[r, black]\arrow[r, blue, end anchor=north east]\arrow[r,red,start anchor={[xshift=-1ex]},end anchor={[yshift=2ex]north east}]& B\end{tikzcd}/tikz/commutative diagrams/shorten=hdimensioni(no default)This key shortens each end of the arrow by hdimensioni.
AB\begin{tikzcd}
A \arrow[r, shift left]\ar[r, shorten=2mm, shift right]& B\end{tikzcd}

Note that the ends of an arrow can be shortened individually using TikZ’s built-in keys shorten < andshorten >.

2.6

Three-dimensional diagrams(style, no value)/tikz/commutative diagrams/crossing overThis style makes a thicker line, with color background color, to be drawn under the current arrow,simulating the effect of its passing over other arrows.
A

B

C

D

\begin{tikzcd}
A \arrow[dr] & B \arrow[dl, crossing over] \\C& D\end{tikzcd}

Note that, since arrows are drawn in the order they are read, it may be necessary to defer the drawing ofcertain arrows to achieve the desired result. This can be done using the from key, as shown in the following
picture.

10

f ∗ EV

EV

f ∗E

E
U

V

M

N

\begin{tikzcd}[row sep=scriptsize, column sep=scriptsize]& f^* E_V \arrow[dl] \arrow[rr] \arrow[dd] & & E_V \arrow[dl] \arrow[dd] \\f^* E \arrow[rr, crossing over] \arrow[dd] & & E \\& U \arrow[dl] \arrow[rr] & & V \arrow[dl] \\M \arrow[rr] & & N \arrow[from=uu, crossing over]\\\end{tikzcd}/tikz/commutative diagrams/crossing over clearance=hdimensioni(no default, initially 1.5ex)

This key specifies the width of the background-colored line drawn under a crossing over arrow.

2.7

Options for labels(style, no value)/tikz/commutative diagrams/every label
This style is applied to every label produced with \arrow. It is initially set to/tikz/auto,/tikz/font=hsomethingi,/tikz/inner sep=0.5ex

where hsomethingi is something that makes \scriptstyle be applied to labels in math mode.
The key /tikz/auto makes the label be placed on the left side of the arrow, relative to its direction. The
key /tikz/inner sep controls the distance between a label and the corresponding arrow.
(no default)/tikz/commutative diagrams/labels=hoptionsiThis key appends hoptionsi to every label.

(style, no value)/tikz/commutative diagrams/marking

This style causes the label to be placed over the arrow. It is useful to decorate arrows using ordinary
math symbols.
A

/
◦

B
C

\begin{tikzcd}
A \arrow[r, "/" marking]\arrow[rd, "\circ" marking]& B \\& C\end{tikzcd}(style, no value)/tikz/commutative diagrams/description

This style causes the label to be placed over the arrow, with the background filled. The clearance aroundthe label is determined by /tikz/inner sep.
A

3

φ

B

\begin{tikzcd}
A \arrow[r, "\phi" description] & B\end{tikzcd}

Advanced usage

This section provides further details on the functioning of this package, with the aim of allowing the advanceduser to make a more or less arbitrary use of other TikZ features within {tikzcd}.
11

3.1

Internals of tikzcd and the arrow commands

The {tikzcd} environment works by substituting code of the form
\begin{tikzcd}[hoptionsi]
hcontentsi\end{tikzcd}
with roughly the following:\begin{tikzpicture}[hoptionsi]\matrix[matrix of nodes] {hcontentsi \\};hpathsi\end{tikzpicture}
Not shown above are a number of initialization procedures, such as defining \arrow and its relatives, aswell as applying the default settings specified by every diagram and its relatives. Note that the next-row
command \\ for the last row is inserted by {tikzcd}, and therefore should not be present in hcontentsi.
Notice also that you can use the key execute at end picture in hoptionsi to have arbitrary TikZ code
executed after a diagram is drawn.
Initially, hpathsi is the empty string. A command \arrow[hoptionsi] does nothing at the point it isinserted, and causes the following code to be appended to hpathsi:\path[hoptionsi] (hsource nodei) to (htarget nodei);
By default, hsource nodei and htarget nodei refer to the node corresponding to the matrix cell where thecommand \arrow is present. This can be changed using the from and to keys, or a direction argument (astring consisting of characters r, l, d, u).

3.2

Tweaking to paths

Recall that the to path operation used in the paths created by \arrow can take a number of options, as
described in §74 of the pgf manual [2]. In particular, the key /tikz/to path determines the path that is
actually drawn, and can be used to do all sorts of fiddling.
A
B\begin{tikzcd}
A \arrow[dr, controls={+(1.5,0.5) and +(-1,0.8)}]\arrow[dr, dashed, to path=|- (\tikztotarget)]& \\& B \arrow[loop right]\end{tikzcd}

The following example shows how to produce a “snake” map. The arrow with the phantom option (goingfrom B to E) has the sole purpose of creating a coordinate, named Z, lying halfway between these two cells.
The arrow starting at C has target D, so the macros \tikztostart and \tikztotarget will expand to thenodes corresponding to these two cells in the argument of to path. Notice also the use of \tikztonodes atthe point where we want the label to be inserted.
A

B

D

E

C
δ

F

12

\begin{tikzcd}
A \arrow[r]& B \arrow[r]\arrow[d, phantom, ""{coordinate, name=Z}]& C \arrow[dll,"\delta",rounded corners,
to path={ -- ([xshift=2ex]\tikztostart.east)|- (Z) [near end]\tikztonodes-| ([xshift=-2ex]\tikztotarget.west)-- (\tikztotarget)}] \\D \arrow[r]& E \arrow[r]& F\end{tikzcd}

3.3

Drawing diagrams directly with TikZ

If you find that this package is not flexible enough for some particular application, you can use the methods
described in [1] and draw diagrams directly with TikZ. In this case, you can still use the styles provided here
to obtain pictures with a uniform appearance throughout your document. The pictures below show how thiscan be done (the second one is adapted from [1]).
X

X̄
Y\begin{tikzpicture}[commutative diagrams/every diagram]\matrix[matrix of math nodes, name=m, commutative diagrams/every cell] {X & \bar X \\& Y\\};\path[commutative diagrams/.cd, every arrow, every label](m-1-1) edge[commutative diagrams/hook] (m-1-2)
edge[commutative diagrams/dashed] (m-2-2)(m-1-2) edge (m-2-2);\end{tikzpicture}X ⊗ (Y ⊗ (Z ⊗ T ))1⊗φφX ⊗ ((Y ⊗ Z) ⊗ T ))(X ⊗ Y ) ⊗ (Z ⊗ T )φ(X ⊗ (Y ⊗ Z)) ⊗ T

φφ⊗1((X ⊗ Y ) ⊗ Z) ⊗ T\begin{tikzpicture}[commutative diagrams/every diagram]\node (P0) at (90:2.3cm) {$X\otimes (Y\otimes (Z\otimes T))$};\node (P1) at (90+72:2cm) {$X\otimes ((Y\otimes Z)\otimes T))$} ;\node (P2) at (90+2*72:2cm) {\makebox[5ex][r]{$(X\otimes (Y\otimes Z))\otimes T$}};\node (P3) at (90+3*72:2cm) {\makebox[5ex][l]{$((X\otimes Y)\otimes Z)\otimes T$}};\node (P4) at (90+4*72:2cm) {$(X\otimes Y)\otimes (Z\otimes T)$};\path[commutative diagrams/.cd, every arrow, every label](P0) edge node[swap] {$1\otimes\phi$} (P1)
(P1) edge node[swap] {$\phi$} (P2)
(P2) edge node {$\phi\otimes 1$} (P3)
(P4) edge node {$\phi$} (P3)
(P0) edge node {$\phi$} (P4);\end{tikzpicture}

3.4

Issues with active characters

By default, TikZ makes the character & active inside matrices, and this causes the error message! Package pgfbasematrix Error: Single ampersand used with wrong catcode.

13

when {tikzcd} is used inside the argument to a macro such as a Beamer frame or a footnote. One solution
to this problem is to call {tikzcd} with the option ampersand replacement=\&, and replace all occurrencesof & with \& in the diagram. This procedure is also needed if you want to use matrices in a diagram cell orlabel.


e

g

A⊕B

f
h




C ⊕D

\begin{tikzcd}[ampersand replacement=\&]A \oplus B \ar[r, "{\begin{pmatrix} e & f \\ g & h \end{pmatrix}}"]\& C \oplus D\end{tikzcd}

An alternative fix to this issue that does not require replacing & with a different column separator consistsin adding the following line to your document after all packages have been loaded:\def\temp{&} \catcode`&=\active \let&=\temp
However, this may interfere in unexpected ways with other packages. Use this trick at your own risk.
A different but related issue is that some packages, notably babel, modify the catcodes of certain
characters in a way that may upset TikZ’s parser. To fix this, add\usetikzlibrary{babel}
to your document preamble.

4

Additional goodies

This package provides some general pgf infrastructure to achieve its goals. These additional goodies are
documented in this section.

4.1

The asymmetrical rectangle shape

The following shape is used inside {tikzcd} to ensure that arrows between nodes in the same row are
perfectly horizontal, even if the nodes contain text with different heights and depths.
Shape asymmetrical rectangle
This shape is similar to the rectangle shape, but its center is located at a fixed distance of the base, as
determined by the center yshift key, rather than lying at the shape’s geometric center. The numericalanchors, as well as east and west, are modified accordingly, and there are anchors called real center,
real east, and real west matching rectangle’s original definitions. All other anchors provided byrectangle are available and remain unmodified.
/tikz/commutative diagrams/center yshift=hdimensioni(no default, initially axis_height)

Determines the distance between asymmetrical rectangle’s base and center anchors.
The picture below shows some of the available anchors.

130

north west

north

north east

10
real west
west
base west

south west

text

real center

real east

centerbase

eastbase east

Asymmetrical rectangle
south

230

14

-10

south east

4.2

Reading font parameters

The following are pgfmath functions used to access relevant math font parameters. They take no arguments,
but the result depends of the currently selected font size.
axis_height
Returns the axis height parameter (a.k.a. σ22 ) of the document’s math font.
rule_thickness
Returns the fraction rule thickness (a.k.a. ξ8 ) of the document’s math font.

4.3

Computer Modern arrow tips

The following arrow tips mimic the Computer Modern designs. It is useful to know that at size 10 pt, theComputer Modern arrow stems are 0.4 pt thick; for other font sizes, scale this parameter accordingly, or set
line width=rule_thickness.
Notice that by using the mechanism explained in §1.3, it is not necessary, and in fact not advisable, todirectly refer to the arrow tips listed in this section inside a {tikzcd}.
cm to
cm implies
cm bold to
cm double to
cm to reversed

4.4

yieldsyieldsyieldsyieldsyieldscm barcm left tocm right tocm left hook
cm right hookyieldsyieldsyieldsyieldsyieldsGlyph arrow tips

As an attempt to provide a general solution to the problem of having matching arrow tips in text and pictures,
this feature produces arrow tips that consist of (pieces of) font glyphs carefully placed at the endpoints of thepath. To activate it in {tikzcd} diagrams, refer to the arrow style key.
Arrow Tip Kind Glyph
An arrow tip made from a piece of text. It accepts the following parameters.
/pgf/arrow keys/glyph math command=hnamei(no default)

The name of a command (to be used inside $\csname …\endcsname$) producing the desired glyph.
/pgf/arrow keys/glyph length=hdimensioni(no default, initially 1ex)
The length of the portion of the glyph not clipped away. Also used to set the ‘tip end’ parameter.
(no default, initially axis_height)/pgf/arrow keys/glyph axis=hdimensioni

A vertical displacement applied to the glyph in order to make the glyph’s central axis (typically anarrow stem) aligned with the path.
/pgf/arrow keys/glyph shorten=hdimensioni(no default, initially -0.1ex)

An additional amount by which the end of the path is shortened. This is used to compensate forthe gap that usually exists between the tip end and the glyph’s bounding box.
Below are some usage examples. Notice that glyph arrow tips do not scale with pgf line width but theirsize depends on the current font size, so you will probably want to set line width=rule_thickness whenusing them. Also, contrarily to the arrow parameters defined by the arrows.meta library, the parametersdescribed above are evaluated only at the time the arrow tip is drawn, so they can (and should) be given in
the units em or ex.

15

" →

→

V

π

π

\tikzset{
math to/.tip={Glyph[glyph math command=rightarrow]},
loop/.tip={Glyph[glyph math command=looparrowleft, swap]},
weird/.tip={Glyph[glyph math command=Rrightarrow, glyph length=1.5ex]},pi/.tip={Glyph[glyph math command=pi, glyph length=1.5ex, glyph axis=0pt]},}\begin{tikzpicture}[line width=rule_thickness]\draw[loop-math to, bend left] (0,2) to (1,2);\draw[math to-weird] (0,1) to (1,1);\draw[pi-pi] (0,0) to (1,0);\end{tikzpicture}

It is important to be aware of some drawbacks of this feature. First, the transition between a line and thearrow tip may become visible with some printers (especially in low resolutions or draft mode) and document
viewers, as you may be able to see in the samples above. Second, these rather long tips may ( →) or may
not ( →) fit nicely with dashed or curved lines. Finally, the method used to place the arrow tip at the endof a stroked path and clip away the arrow stem makes certain assumptions about the font design and could
fail in cases where unusual design choices are made.

References[1] James Milne, Guide to commutative diagrams. Available at http://www.jmilne.org/not/CDGuide.html.
[2] Till Tantau, The TikZ and pgf packages: Manual for version 3.1.9. Available at http://mirrors.ctan.
org/graphics/pgf/base/doc/pgfmanual.pdf.

16

IndexThis index only contains automatically generated entries. A good index should also contain carefully selected
keywords. This index is not a good index.
\ar, 2\arrow, 2, 4
arrow style key, 8
Arrow tips
cm bar, 15
cm bold to, 15
cm double to, 15cm implies, 15
cm left hook, 15
cm left to, 15
cm right hook, 15
cm right to, 15
cm to, 15
cm to reversed, 15Glyph, 15arrows key, 7
asymmetrical rectangle shape, 14
axis_height math function, 15

every matrix key, 6
from key, 8Glyph arrow tip, 15
glyph axis key, 15
glyph length key, 15
glyph math command key, 15
glyph shorten key, 15
harpoon key, 4
harpoon' key, 4hook key, 4hook' key, 4hookleftarrow key, 4hookrightarrow key, 4labels key, 11\lar, 4
Leftarrow key, 3
leftarrow key, 3
leftarrowtail key, 4
leftharpoondown key, 4
leftharpoonup key, 4
Leftrightarrow key, 3
leftrightarrow key, 3
leftrightsquigarrow key, 4
leftsquigarrow key, 4
Libraries
cd, 1, 5background color key, 7
cd library, 1, 5
cells key, 6center yshift key, 14
cm bar arrow tip, 15
cm bold to arrow tip, 15
cm double to arrow tip, 15cm implies arrow tip, 15
cm left hook arrow tip, 15
cm left to arrow tip, 15
cm right hook arrow tip, 15
cm right to arrow tip, 15
cm to arrow tip, 15
cm to reversed arrow tip, 15
column sep key, 6
cramped key, 7crossing over key, 10
crossing over clearance key, 11

maps to key, 3Mapsfrom key, 3
mapsfrom key, 3
Mapsto key, 3
mapsto key, 3
marking key, 11
Math functions
axis_height, 15
rule_thickness, 15
math mode key, 7\dar, 4dash key, 4dashed key, 4
dashleftarrow key, 4
dashrightarrow key, 4description key, 11diagrams key, 6\dlar, 5\drar, 4

no head key, 4
no tail key, 4
Packages and files
tikz-cd, 1/pgf/
arrow keys/
glyph axis, 15
glyph length, 15
glyph math command, 15
glyph shorten, 15
phantom key, 9

end anchor key, 10
Environments
tikzcd, 2, 5
equal key, 4
every arrow key, 7
every cell key, 6
every diagram key, 6
every label key, 11\rar, 4Rightarrow key, 3rightarrow key, 317rightarrowtail key, 4rightharpoondown key, 4rightharpoonup key, 4rightsquigarrow key, 4
row sep key, 6
rule_thickness math function, 15

marking, 11math mode, 7
no head, 4
no tail, 4phantom, 9
Rightarrow, 3
rightarrow, 3
rightarrowtail, 4rightharpoondown, 4rightharpoonup, 4
rightsquigarrow, 4
row sep, 6
sep, 7shift, 9shift left, 9
shift right, 9shorten, 10
squiggly, 4
start anchor, 10
tail, 4
to, 8
to head, 3
two heads, 4
twoheadleftarrow, 4
twoheadrightarrow, 4xshift, 9yshift, 10tikz-cd package, 1tikzcd environment, 2, 5\tikzcdset, 5
to key, 8
to head key, 3
two heads key, 4
twoheadleftarrow key, 4
twoheadrightarrow key, 4

sep key, 7
Shapesasymmetrical rectangle, 14
shift key, 9shift left key, 9shift right key, 9shorten key, 10
squiggly key, 4
start anchor key, 10
tail key, 4/tikz/
commutative diagrams/
arrow style, 8
arrows, 7
background color, 7cells, 6center yshift, 14
column sep, 6
cramped, 7crossing over, 10
crossing over clearance, 11dash, 4
dashed, 4
dashleftarrow, 4
dashrightarrow, 4description, 11
diagrams, 6
end anchor, 10
equal, 4every arrow, 7
every cell, 6
every diagram, 6
every label, 11
every matrix, 6
from, 8
harpoon, 4
harpoon', 4
hook, 4hook', 4hookleftarrow, 4hookrightarrow, 4labels, 11
Leftarrow, 3
leftarrow, 3
leftarrowtail, 4
leftharpoondown, 4
leftharpoonup, 4
Leftrightarrow, 3
leftrightarrow, 3
leftrightsquigarrow, 4
leftsquigarrow, 4maps to, 3
Mapsfrom, 3
mapsfrom, 3Mapsto, 3
mapsto, 3\uar, 4
\ular, 5\urar, 5xshift key, 9yshift key, 1018