13

I would like to learn to make commutative rectangles using Tikz. How can I do that? I have tried

\[\begin{tikzcd}
A \arrow{r}{\varphi} \arrow[swap]{dd}{g\circ f} & B \arrow{d}{g} \\
& C
\end{tikzcd}
\]

but it draws only a triangle.

4

3 Answers 3

8

I don't know what you exactly wanted to draw, so I reproduce one of the diagrams from your link, showing how to do it with pst-node and with tikz-cd. One of the main differences is that in pstricks you first describe the nodes, then the arrows, while with tikz-cd, nodes and arrows are described simultaneously.

I load auto-pst-pdf, as pdflatex doesn't support postscript instructions. You have to set the --enable-write18 compiler switch (MiKTeX) or -shell-escape (TeX Live, MacTeX). Alternatively, you can compile with xelatex.

\documentclass{article}
\usepackage{pst-node}
\uspackage{auto-pst-pdf}
\usepackage{tikz-cd} 

\begin{document}
%
 \[ \psset{arrows=->, arrowinset=0.25, linewidth=0.6pt, nodesep=3pt, labelsep=2pt, rowsep=0.7cm, colsep = 1.1cm, shortput =tablr}
 \everypsbox{\scriptstyle}
 \begin{psmatrix}
 A & B\\%
 A_f & B_g
 %%%
 \ncline{1,1}{1,2}^{\varphi} \ncline{1,1}{2,1} <{\varrho_f }
 \ncline{1,2}{2,2} > {\varrho_g}
 \ncline{2,1}{2,2}^{\varphi_f}
 \end{psmatrix}
 \]

\[ \begin{tikzcd}
A \arrow{r}{\varphi} \arrow[swap]{d}{\varrho_f} & B \arrow{d}{\varrho_g} \\%
A_f \arrow{r}{\varphi_f}& B_g
\end{tikzcd}
\]
\end{document} 

enter image description here

8
  • This code does not work for me. It does not produce any of the labels ϱ_f and ϱ_g under xelatex and under pdflatex or lualatex it will not run at all.
    – Paulo Ney
    Commented Mar 16, 2019 at 13:07
  • There have been changes in pstricks since then. Try removing the [pdf] option and load auto-pst-pdf (after pstricks).
    – Bernard
    Commented Mar 16, 2019 at 13:12
  • Nope! It will not run under any of the modern tex engines.
    – Paulo Ney
    Commented Mar 16, 2019 at 13:20
  • Did you try xelatex?
    – Bernard
    Commented Mar 16, 2019 at 13:48
  • @PauloNey: I'm sorry, there was a problem with my editor at the time, which I hadn't noticed: the TeX code for Greek letters had been replaced with real Greek letters (in the code). I've just fixed it. Could you try the updated code?
    – Bernard
    Commented Mar 16, 2019 at 13:59
9

Purely with Plain TeX math mode:

\catcode`\@=11
\newdimen\cdsep
\cdsep=3em

\def\cdstrut{\vrule height .6\cdsep width 0pt depth .4\cdsep}
\def\@cdstrut{{\advance\cdsep by 2em\cdstrut}}

\def\arrow#1#2{
  \ifx d#1
    \llap{$\scriptstyle#2$}\left\downarrow\cdstrut\right.\@cdstrut\fi
  \ifx u#1
    \llap{$\scriptstyle#2$}\left\uparrow\cdstrut\right.\@cdstrut\fi
  \ifx r#1
    \mathop{\hbox to \cdsep{\rightarrowfill}}\limits^{#2}\fi
  \ifx l#1
    \mathop{\hbox to \cdsep{\leftarrowfill}}\limits^{#2}\fi
}
\catcode`\@=12

\cdsep=3em
$$
\matrix{
  A                    & \arrow{r}{\varphi}   & B                    \cr
  \arrow{d}{\varrho_f} &                      & \arrow{d}{\varrho_g} \cr
  A_f                  & \arrow{r}{\varphi_f} & B_g                  \cr
}
$$

\bye

enter image description here

8

OK. I learned to make commutative rectangles.

\[\begin{tikzcd}
A_f \arrow{r}{\varphi_f} \arrow[swap]{d}{\varrho_x^f} & B_g \arrow{d}{\varrho_x^g} \\
A_x \arrow{r}{\varphi_y} & B_y
\end{tikzcd}
\]
0

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