# How to label/tag TikZ diagrams?

I would like to be create diagrams using TikZ that have a number on the side of the page (like the equation environment makes) that I can label using \label and cross-reference using \ref.

Essentially, I am looking for something like \tag that works inside the tikzpicture environment.

For a concrete example, I would like to create something like the first two diagrams on the following page.

Does anyone know how this can be done in TikZ specifically?

You can put everything you like into the equation environment. Like this, it will behave like an equation which seems to be what you want.

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{blindtext}

\begin{document}
\setcounter{page}{15}
\noindent
into a commutative diagramm
$$\begin{tikzcd} B\times_A C \arrow{r}{\pi_2}\arrow{d}[swap]{\pi_1} & C\arrow{d}{g} \\ B \arrow{r}[swap]{f} & A; \end{tikzcd}$$
\blindtext

In a general category $C$, one says that a commutative square
$$\begin{tikzcd} P \arrow{r}{q}\arrow{d}[swap]{p} & C\arrow{d}{g} \\ B \arrow{r}[swap]{f} & A \end{tikzcd}$$
\blindtext
\end{document}


If you which to have the last diagram as well:

\begin{equation*}
\begin{tikzcd}
X\arrow{drr}{\gamma}\arrow[dashed]{dr}[near end]{!\delta}\arrow{ddr}[swap]{\beta} & & \\[1ex]
& P \arrow{r}{q}\arrow{d}[swap]{p} & C\arrow{d}{g} \\
& B \arrow{r}[swap]{f} & A
\end{tikzcd}
\end{equation*}

• Thank you! This is exactly what I was looking for. I can't believe I never tried sticking a TikZ environment inside equation... – Artem Mavrin Sep 11 '15 at 10:19
• @ArtemMavrin Glad to hear that. Sometimes, things are that clear that one can oversee them... :-) – LaRiFaRi Sep 11 '15 at 10:24