You almost had it.
Remove the &
from the first row. You want the X
to be in the first column above the X|S
and remove one of the &
in the second row.
Of course, you need to adjust the directional statements then as well.
The dr
becomes d
, the rr
becomes r
and the ur
would become r
.
But since you want that arrow to go from X
to X|S
you ought to put the \arrow[d, "\pi"]
there (or \arrow[u, "\pi", leftarrow]
in the X|S
cell if that makes more sense from a syntactial point of view).
I've also added a '
after the "\hat{a}_i"
statement so that the label is placed on the other side of the arrow.
The same applied for the \pi
label in case you construct the arrow from X
to X|S
.
The body of the tikzcd
environment can be treated like a tabular
/array
where &
separates the columns.
The \arrow
macro starts an arrow in that cell with the target according to the directional shortcut. (Unless keys like from
and to
are used.)
By default, all arrows use the rightarrow
style which can be inverted by using leftarrow
. For more on this, I'd recommend reading the manual.
Code
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}
X \arrow[dr, "a_i"] \arrow[d, "\pi"']\\
X|S \arrow[r,"\hat{a}_i"'] & R
\end{tikzcd}
\]
\end{document}
Output
