# Add caption for diagram in tikz cd

consider the following code.

\documentclass[14pt,reqno,a4paper]{amsart}
\usepackage{extsizes}
\usepackage{blindtext}
\textheight 9.3in \textwidth 6.5in
\calclayout
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{hyperref}
\usepackage{mathrsfs}
\usepackage[all]{xy}
\usepackage[normalem]{ulem}
\usepackage{tikz-cd}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newcommand{\uMor}[1]{\operatorname{\underline{Mor_{#1}}}}
\usepackage{color}
\begin{document}
\begin{tikzcd}
(\mathcal{C}/U)^{\text{op}} \arrow[rrr, "{\uMor{\mathcal{F}}(x,y)}"{name=U}, bend left=49] \arrow[rrr, "{\uMor{\mathcal{G}}(\Psi(x),\Psi(y))}"'{name=D}, bend right=49] &  &  & (\text{Set})
\arrow[Rightarrow, from=U, to=D, shorten >=2pt, shorten <=2pt]
\end{tikzcd}
\end{document}


I want to add caption for a diagram in tikzcd code.

I want to name the figure say “Figure 1”

What are some ways to do that?

• Why not put it into a figure environment and use the usual \caption approach. An alternative would be using the \captionof{figure}{...} command from the capt-of package. – leandriis Feb 23 at 14:52
• I am not really very comfortable with this kind of things. Can you write in detail in an answer. @leandriis thank you – Praphulla Koushik Feb 23 at 14:53

\documentclass[14pt,reqno,a4paper]{amsart}
\usepackage{extsizes}
\textheight 9.3in \textwidth 6.5in
\calclayout
\usepackage{tikz-cd}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newcommand{\uMor}[1]{\operatorname{\underline{Mor_{#1}}}}
\usepackage{capt-of}
\begin{document}

\begin{figure}
\begin{tikzcd}
(\mathcal{C}/U)^{\text{op}} \arrow[rrr, "{\uMor{\mathcal{F}}(x,y)}"{name=U}, bend left=49] \arrow[rrr, "{\uMor{\mathcal{G}}(\Psi(x),\Psi(y))}"'{name=D}, bend right=49] &  &  & (\text{Set})
\arrow[Rightarrow, from=U, to=D, shorten >=2pt, shorten <=2pt]
\end{tikzcd}
\caption{my caption text}
\end{figure}

\begin{center}
\begin{tikzcd}
(\mathcal{C}/U)^{\text{op}} \arrow[rrr, "{\uMor{\mathcal{F}}(x,y)}"{name=U}, bend left=49] \arrow[rrr, "{\uMor{\mathcal{G}}(\Psi(x),\Psi(y))}"'{name=D}, bend right=49] &  &  & (\text{Set})
\arrow[Rightarrow, from=U, to=D, shorten >=2pt, shorten <=2pt]
\end{tikzcd}
\captionof{figure}{my caption text}
\end{center}

\end{document}


Unrelated to the question, but you might want to keep in mind that the hyperref package should generally (with some few exceptions) be the last package that you load.

• Does the samething works if I want to write as equation? $$\begin{tikzcd}\end{tikzcd}$$?? – Praphulla Koushik Feb 24 at 0:51
• @PraphullaKoushik: Yes, it does. Did you try this yourself? – leandriis Feb 24 at 9:05
• It did not work... :O That is why I asked... It did not work for me atleast... – Praphulla Koushik Feb 24 at 9:07
• If I use the preamble from your question and insert the tikzcd environment into an equation environment, I get the following result: i.stack.imgur.com/NcHoF.png – leandriis Feb 24 at 9:09
• Yes, that I also got.. I want the diagram look like the one above with a caption and also equation number as 1 ... – Praphulla Koushik Feb 24 at 9:13