0

Consider

\begin{tikzcd}
F(X) \arrow[r, "F(f)"] \arrow[d, "\eta_X"'] & F(Y) \arrow[d, "here is a really long sentence"] \\
G(X) \arrow[r, "G(f)"'] & G(Y)
\end{tikzcd}

I want to make the text describing the down right arrow break in two lines. I have tried \\ and \newline, but this doesn't work, unfortunately.

Torbjørn T.
  • 206,688
Mark
  • 265

2 Answers2

5

You can do that with a \parbox:

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

\begin{document}

\begin{tikzcd}
F(X) \arrow[r, "F(f)"] \arrow[d, "\eta_X"'] & F(Y) \arrow[d, "\scriptsize\parbox{2cm}{here is a really long sentence}"] \\
G(X) \arrow[r, "G(f)"'] & G(Y)
\end{tikzcd}

\end{document} 

enter image description here

Bernard
  • 271,350
2

\\ or \newline doesn't, by default, work in any TikZ node, cf. Manual/automatic line breaks and text alignment in TikZ nodes. From that question you'll see that if you set align=left (or center, or right), then you can use \\. In this context, you'll need to do

"long \\ text"align=left

If you have actual text in that label, and not a mathematical expression, you also need to switch to text mode:

"\text{long} \\ \text{text}"align=left

The \text macro comes from amsmath.

You might also want to move the label away from the line a bit, and for that you can do for example

"\text{long} \\ \text{text}"{align=left,right=2mm}

Note the extra braces, used to indicate that both the options belong to the "text". In the complete example below, I also reduced the font size, like Bernard did in his answer.

output of code

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
F(X) \arrow[r, "F(f)"] \arrow[d, "\eta_X"'] & F(Y)
   \arrow[d, "\text{here is a} \\ \text{really long sentence}"{align=left,right=2mm,font=\scriptsize}] \\
G(X) \arrow[r, "G(f)"'] & G(Y)
\end{tikzcd}
\end{document}
Torbjørn T.
  • 206,688