How can I align nodes and have arrows of the same length in tikz-cd?
You only need to adjust the text width of the nodes. (In the original version of this answer I forgot to apply this only to the nodes in the cells. The correct syntax is cells={...}
, and not nodes={...}
which applies the width also to the labels, which are nodes, too.)
\documentclass[12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,tikz-cd}
\begin{document}
\begin{tikzcd}[cells={text width={width("$A\otimes A\otimes A$")},align=center},
column sep=4em]
A \arrow[d,"\mu_0"] \arrow[r,"\mu_0"] & A\otimes A \arrow[d,
"\mu_0\otimes\text{Id}"]\\
A\otimes A \arrow[r, "\text{Id}\otimes \mu_0"] & A\otimes A\otimes A
\end{tikzcd}
\end{document}
A solution based on eqparbox
, which adds a system of tags toor the usual box constructs. All boxes sharing the same tag have the same width (the natural width of the box with this tag and the widest contents).
Unrelated: some of the packages you load are already loaded by others, so I removed them. Aldo, hyperref
should be loaded as the last package, with very few exceptions, most notably cleveref
.
\documentclass[12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage{cite, mathtools, amssymb, xcolor, ulem, amsthm, enumitem, tikz-cd}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][N]{\eqmakebox[#1]{$\displaystyle#2$}}
\usepackage{hyperref, cleveref}
\begin{document}
\begin{tikzcd}
\eqmathbox{A} \arrow[d,"\mu_0"] \arrow[r,"\mu_0"] & \eqmathbox[M]{A\otimes A} \arrow[d,"\mu_0\otimes\mathrm{Id}"]\\
\eqmathbox{A\otimes A} \arrow[r, "\mathrm{Id}\otimes \mu_0"] & \eqmathbox[M]{A\otimes A\otimes A}
\end{tikzcd}
\end{document}