Linebreak inside label - tikzcd package

Use \substack.

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

\begin{document}

\begin{tikzcd}[row sep=large]
  A \arrow[d, "\substack{a \\ a}"] & % good
  A \arrow[d,"a \\ a" align=left] &  % bad
  A \arrow[d,"\shortstack{a\\a}"]    % ugly
\\
  B & B & B
\end{tikzcd}

\end{document}

enter image description here

If the labels are textual, use \text inside \substack. The same code as before, but with \substack{\text{a} \\ \text{a}} in the leftmost arrow yields

enter image description here


\documentclass{book}
\usepackage{tikz-cd,amsmath}
\begin{document}
    \begin{tikzcd}[row sep=3cm]
        A \arrow[d, "\shortstack{label 1\\label 2}"] \\
        B
    \end{tikzcd}
\end{document}

enter image description here


You only need to add align=left (or something of that sort).

\documentclass{article}
\usepackage{tikz-cd,amsmath}
\begin{document}
\begin{tikzcd}[row sep=3cm]
A \arrow[d,"label1\\ label2"align=left] \\
B
\end{tikzcd}
\end{document}

enter image description here