[Tex/LaTex] How to label/tag TikZ diagrams

cross-referencinglabelstikz-pgf

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.
enter image description here

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

Best Answer

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{equation}
    \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}
\end{equation}
\blindtext

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

enter image description here


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*}
Related Question