# Standard align space with CD environment from amscd package

I have the following code:

\begin{align}
foo &=\mydiagram{\text{width width}}       & bar &= \mydiagram{\text{width width width}}
\\[\jot]
foo &=\mydiagram{\text{width width width}} & bar &= \mydiagram{\text{width}}
\end{align}


where \mydiagram{} is a diagram composed with the CD environment from amscd package and it's defined as follows:

\def\mydiagram#1{%
\begin{CD}
S^{{\mathcal{W}}_\Lambda}\otimes T
@>j>>
T\\
@V{#1}VV
@VV{\End P}V\\
(S\otimes T)/I
@=
(Z\otimes T)/J
\end{CD}%
}


It follows my output:

I have used align environment because it calculates correct spaces between columns by himself, but not in this case. How can I fix spaces in order to have standard align environment behaviour?

MWE

\documentclass[a4paper,11pt]{article}

\usepackage{amsmath}
\usepackage{amscd}

\DeclareMathOperator{\End}{End}

\def\mydiagram#1{%
\begin{CD}
S^{{\mathcal{W}}_\Lambda}\otimes T
@>j>>
T\\
@V{#1}VV
@VV{\End P}V\\
(S\otimes T)/I
@=
(Z\otimes T)/J
\end{CD}%
}

\begin{document}

\begin{align*}
foo &=\mydiagram{\text{width width}}       & bar &= \mydiagram{\text{width width width}}
\\[\jot]
foo &=\mydiagram{\text{width width width}} & bar &= \mydiagram{\text{width}}
\end{align*}

\end{document}

• You should use tikz-cd which does a much better job and has a simpler syntax. – Bernard Jan 16 '18 at 15:52
• @Bernard Thank you! I have imaged that tikz-cd would have been better than CD, but unfortunately this choice it is not depend on me. – Onner Irotsab Jan 16 '18 at 17:39

Putting an \fbox around the CD environment reveals that the label sticks out the bounding box. Therefore add space to your \diagram macro to accommodate the label

\documentclass[a4paper,11pt]{article}

\usepackage{amsmath}
\usepackage{amscd}
\usepackage{geometry}

\DeclareMathOperator{\End}{End}

\def\mydiagram#1{%
\hphantom{\scriptstyle #1}\mkern-28mu\begin{CD}
S^{{\mathcal{W}}_\Lambda}\otimes T
@>j>>
T\\
@V{#1}VV
@VV{\End P}V\\
(S\otimes T)/I
@=
(Z\otimes T)/J
\end{CD}%
}

\begin{document}

\begin{align*}
foo &=\mydiagram{\text{width width}}       & bar &= \mydiagram{\text{width width width}}
\\[\jot]
foo &=\mydiagram{\text{width width width}} & bar &= \mydiagram{\text{width}}
\end{align*}

\end{document}


Of course the result is too wide for the page, so you should not put too many of these on one line.