5

I am using tikzcd.
I want to use line breaks within the label of the arrows. Naively, I thought that

\begin{tikzcd}
  A \arrow[d, "label 1 \\ label 2"] \\
  B
\end{tikzcd}

would work. But it gives me

enter image description here

instead. How to solve this?

5

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

5
\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

5

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

3

From the pag. 13 of the guide of tikz-cd http://ctan.math.washington.edu/tex-archive/graphics/pgf/contrib/tikz-cd/tikz-cd-doc.pdf

enter image description here

I have used a matrix 2x1 (for example) to have two vertical labels. With the option row sep=...cm you can increase or decrease the lenght of the arrow.

enter image description here

\documentclass[a4paper,12pt,oneside]{book}
\usepackage{tikz-cd,amsmath}
\begin{document}
\begin{tikzcd}[row sep=2cm, ampersand replacement=\&]
A \arrow[d, "{\begin{matrix} \text{label1} \\ \text{label2} \end{matrix}}
"] \\
B
\end{tikzcd}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.