How can I align without spaces

When I use this text in TexShop or on math stack exchange (MathJax),

I get this alignment

How can I align these "parts" without the extra spaces?

• Note that TeXShop is an editor for TeX files and is not responsible for the resulting alignment. And MathJax is generally offtopic on this site, since it uses TeX syntax, but not actual TeX under the hood. Jan 18, 2023 at 18:47

You can explicitly leave the space that you want:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
A &= (2n-1)^2 + 2(2n-1)k \\
B &= \phantom{(2n-1)^2+{}} 2(2n-1)k + 2k^2 \\
C &= (2n-1)^2 + 2(2n-1)k + 2k^2
\end{align*}
\end{document}


You don't really need to adjust the spacing with +2k^2, since there's nothing else to line up with. As with the other solution, the {} is to force the + to have the right spacing.

You want to use alignat, but with the right spacing.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{3}
A &= (2n-1)^2 + {} && 2(2n-1)k \\
B &=               && 2(2n-1)k + {} & 2k^2 \\
C &= (2n-1)^2 + {} && 2(2n-1)k + {} & 2k^2
\end{alignat*}

\end{document}


The {} bits are needed to ensure correct spacing around +

• It was a tough call. Your answer and Teepeemm's both solved the problem but the latter provided the same subtle aesthetics without the extra {} brackets. I have copied both methods into a Junk tex doc to save for future reference. Jan 18, 2023 at 19:18