# Tags for rows in a commutative diagram using tikz-cd

Consider a commutative diagram such as

\documentclass{scrartcl}
\usepackage{mathtools, tikz-cd}
\begin{document}
$$\begin{tikzcd} 0 \rar & A \dar \rar & B \dar \rar & C \dar \rar & 0 &[3em] \text{(\textit{i})}\\ 0 \rar & A' \rar & B' \rar & C' \rar & 0 & \text{(\textit{ii})} \end{tikzcd}$$
\end{document}


As you can see, I'd like to add labels to the rows of the diagram. Now, you'll agree that this solution is rather ugly. Is it possible to add labels to the rows that appear at the margin; i.e., instead of what you see, I'd like to have, e.g., Which I produced using

\documentclass{scrartcl}
\usepackage{mathtools, amsmath, tikz-cd}
\tikzset{every picture/.append style={remember picture}}
\begin{document}
\begin{gather}
\begin{tikzcd}[ampersand replacement=\&]
0 \rar \& |[alias=A]|  A \rar \& B \rar \& C \rar \& 0
\end{tikzcd}\\
\begin{tikzcd}[ampersand replacement=\&]
0 \rar \& A' \ar[from=A] \rar \& B' \rar \& C' \rar \& 0
\end{tikzcd}
\end{gather}
\end{document}


which is certainly not the way to go, since it is not particularly stable, and the proper alignment of the cells, which I was too lazy fore here, will be a mess.

• Unrelated: your use of \text in the first example makes no sense at all. \text should never be used to make something non-italic, because that is not what \text does. Mar 9 at 10:53
• @daleif I always thought \text is for putting text in math, and a label is certainly closer to text than to math. And who tells you that I don't want the labels match the surrounding text shape? :P But yes, that's not the point of my question. Mar 9 at 13:14
• I only not it becase a lot of users seems to think that this is the right tool to write something update in math mode and as you mention it is not. Mar 9 at 13:38

You don't really need tikz-cd for this kind of diagrams. Here is a way to do it with alignatand \rotatebox.

Unrelated: you don't have to load amsmath when you load mathtools, since the latter does it for you.

\documentclass{scrartcl}
\usepackage{mathtools}

\begin{document}

\begin{alignat}{4}
0 \xrightarrow{\hskip 2em}{} & A & \xrightarrow{\hskip 2em} {}& B & \xrightarrow{\hskip 2em}{} & C \xrightarrow{\hskip 2em} 0 \\[-1ex]
& \,\rotatebox[origin=c]{-90}{${} \xrightarrow{\hskip 2em}{}$} & & \,\rotatebox[origin=c]{-90}{${} \xrightarrow{\hskip 2em}{}$} & & \,\rotatebox[origin=c]{-90}{${} \xrightarrow{\hskip 2em}{}$} \notag \\[-1ex]
0\xrightarrow{\hskip 2em}{} & A' &\xrightarrow{\hskip 2em} {}& B' & \xrightarrow{\hskip 2em}{} & C' \xrightarrow{\hskip 2em} 0
\end{alignat}

\end{document}


• Sure, but what about more complicated diagrams? Mar 9 at 17:09
• @Bubaya: What do you mean exactly with ‘more complicated diagrams’? One I think of is the Snake lemma (a tool for Homological Algebra), which I make with pstricks preferably. Mar 10 at 9:16
• I'd say that the solution has several other problems; what do you do if the lengths of the entries largely differ? Then you'd have to adjust all the arrow lengths until it looks okay. How does pstricks come to help here? Mar 10 at 14:29
• @Bubaya: for the example I gave, I mainly thought of the S-shaped arrow form the last non-zero term in the first row to the first non-zero term in the second row. This being said, in case of entries with different lengths, you can use the psmatrix environment. Each entry is a node and you can use node connections between these entries. Mar 10 at 16:20