5

I was wondering how to draw the commutative diagram of the following figure. The closest I could get from previous posts is given in the code below, but it is not quite right.

enter image description here

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

\begin{document}
    \[
    \begin{tikzcd}
        & X \arrow[dr,"a_i"] \\
        X|S \arrow[ur,"\pi"] \arrow[rr,"\hat{a}_i"] && R
    \end{tikzcd}
    \]
\end{document}

2 Answers 2

7

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

enter image description here

3
  • That's great! Thank you @Qrrbrbirlbel. Would you please let me know how to make it wider (horizontally), and maybe longer (vertically)?
    – AEW
    Jun 17 at 22:12
  • 1
    @AEW Use the keys column sep and row sep. They are explained very well in the manual. Besides normal dimensions, they also have some predefined ones like row sep=large. Jun 17 at 22:22
  • OK, thanks @Qrrbrbirlbel.
    – AEW
    Jun 17 at 22:24
2

You can consider also to use xy package that have the same structure of tikz-cd and also the same tips. See the output and the MWE.

\documentclass[a4paper,12pt]{article}
\usepackage[all,cmtip]{xy}
\begin{document}
$\xymatrix{
X\ar[dr]^{a_i}  \ar[d]_{\pi}  \\
X/S \ar[r]_{\hat{a}_i} & R}$
\end{document}

enter image description here

follow up

You can increase o reduce the rows @R=2cm or the columns @C=2.5cm. (2cm,2.5cm) are the measures.

\documentclass[a4paper,12pt]{article}
\usepackage[all,cmtip]{xy}
\begin{document}
$\xymatrix@R=2cm@C=2.5cm{
X\ar[dr]^{a_i}  \ar[d]_{\pi}  \\
X/S \ar[r]_{\hat{a}_i} & R}$
\end{document}

enter image description here

6
  • 1
    Thank you, @Sebastiano. Would it be possible to make it wider (horizontally) and longer (vertically)?
    – AEW
    Jun 18 at 22:50
  • @aew yes Is possible
    – Sebastiano
    Jun 19 at 9:00
  • 1
    Would you please let me know how to do that?
    – AEW
    Jun 19 at 19:22
  • 1
    @AEW Now you can see the variations in the second code.
    – Sebastiano
    Jun 19 at 19:29
  • Thank you, @Sebastiano.
    – AEW
    Jun 19 at 21:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .