3

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

I get this alignment

enter image description here

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

1
  • 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.
    – Teepeemm
    Jan 18, 2023 at 18:47

2 Answers 2

3

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.

output

6

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 +

enter image description here

1
  • 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.
    – poetasis
    Jan 18, 2023 at 19:18

You must log in to answer this question.

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