# text in commutative diagrams

How can I replace letters with text or say a text box. Consider the following example. As you might notice in the output, the text is not quite okay. Is there a way to correct it please?

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,calc,shapes.misc,decorations.markings}
\tikzset{degil/.style={
decoration={markings,
mark= at position 0.5 with {
\node[transform shape] (tempnode) {$\backslash$};
%\draw[thick] (tempnode.north east) -- (tempnode.south west);
}
},
postaction={decorate}
}
}

\begin{document}

\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
Stochastic Independence \arrow{ur}   &   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}

\end{document}
-
\text{Stochastic Independence} (with \usepackage{amsmath}), which is the standard way for adding normal text in math formulas. – egreg Aug 13 '14 at 20:46

Here are two possibilities, using mathtools and stackengine:

\documentclass{article}
\usepackage{mathtools}
\usepackage{stackengine}
\setstackEOL{\\}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,calc,shapes.misc,decorations.markings}
\tikzset{degil/.style={
decoration={markings,
mark= at position 0.5 with {
\node[transform shape] (tempnode) {$\backslash$};
%\draw[thick] (tempnode.north east) -- (tempnode.south west);
}
},
postaction={decorate}
}
}

\begin{document}

\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
\fbox{\Centerstack[l]{Stochastic\\Independence}}\arrow{ur}   &   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}
\vskip 1cm
\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
\Centerstack[l]{Stoch\rlap{astic}\\\rlap{Independence}}\arrow{ur}   &   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}

\end{document}

-
Very interesting! Thanks so much Bernard. While I see stuff related to rlap and centerstack etc in the manual, would it be possible for you to explain in very simple words what do these macros(?) do? – Abhimanyu Arora Aug 13 '14 at 21:25
\rlap and \llap are plain TeX macros. Roughly explained from my code, typing Stoch\rlap{astic}inserts Stochastic, but the astic part has 0pt width, hence it is as though the inserted word were only Stoc, hence the point of application of the double arrow. \llap does the same, but in the opposite direction. \Centerstack (from the stackengine package) stacks lines of text and centres the result vertically with respect to the base line. – Bernard Aug 13 '14 at 21:42
Wonderful, I'll try it out to make my diagram a bit more elegant! Thanks and cheers – Abhimanyu Arora Aug 13 '14 at 21:52
Let me mention that these ‘lap commands’ work only in text mode, but the mathtools package (which should be loaded instead of amsmath which it loads anyway) defines a \mathrlap and a \mathllap commands, and adds a \clap and a \mathclap commands, the latter being very useful whan you have long summation indices. You should take a look at Mathmode to learn how to fine tune math typing. – Bernard Aug 13 '14 at 21:59
I see, thanks very much indeed Bernard! I am about to post another question for which I suspect this new thing that I have encountered (thanks to your kind help) may be relevant. – Abhimanyu Arora Aug 13 '14 at 22:04

There's no need for other packages, except perhaps amsmath that's recommended anyway when math is used in a document.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,calc,shapes.misc,decorations.markings}

\tikzset{degil/.style={
decoration={markings,
mark= at position 0.5 with {
\node[transform shape] (tempnode) {$\backslash$};
%\draw[thick] (tempnode.north east) -- (tempnode.south west);
}
},
postaction={decorate}
}
}

\begin{document}

\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
\text{Stochastic Independence} \arrow{ur}   &   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}

\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
\begin{tabular}{@{}c@{}}Stochastic\\ Independence\end{tabular} \arrow{ur}
&   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}

\begin{tikzcd}[arrows=Rightarrow]
&  B \arrow[degil,shift left=1.5ex]{dr}{}  &  \\
\fbox{\begin{tabular}{@{}c@{}}Stochastic\\ Independence\end{tabular}} \arrow{ur}
&   & C \arrow [shift left=.5ex]{ul} \\
& D \arrow{ur} &
\end{tikzcd}

\end{document}

-
Fantastic Enrico! Very nice. Grazie – Abhimanyu Arora Aug 13 '14 at 21:37