5

I have a small commutative diagram with nodes of varying text length. This causes the arrows between columns to be of different lengths. Basically I want each node along a column to be centred so that all arrows would be of the same length. Thanks for the help!

\documentclass[12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage{cite, amssymb, amsmath, xcolor, amsfonts, hyperref, ulem, amsthm, enumitem, cleveref, tikz, mathtools,tikz-cd}
\begin{document}
\begin{tikzcd}
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}

2 Answers 2

4

A solution based on eqparbox, which adds a system of tags to 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. Also, 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} 

enter image description here

1
  • Thanks a lot for the help!
    – wateryeyes
    Jul 5, 2019 at 3:52
8

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}

enter image description here

You must log in to answer this question.

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