5

I am trying to align the + symbols, while also aligning the = symbols, as such

enter image description here

As you can see, I managed to align at the ='s but not the +'s, how can I do that? This is the code I used (using quad to kind of align them):

                x &= a + b (ert)\\
            &\quad\quad + c(ert)\\
            &= abc

When I try something like this:

            x &= a &&+ b (ert)\\
            & &&+ c(ert)\\
            &= abc

I get this: enter image description here

I also tried alignat, and split inside align, but nothing seems to do the trick.

Tom
  • 117
  • 5

3 Answers3

6

You could use alignat but as you want the wrapped summation to overlap the abc on the last row, a nested aligned is better

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

alignat \begin{alignat}{-1} x &= a &&+ b (ert)\ & &&+ c(ert)\nonumber\ &= abc
\end{alignat}

aligned \begin{align} x &=\begin{aligned}[t] a &+ b (ert)\ &+ c(ert) \end{aligned}\ &= abc
\end{align}

\end{document}

David Carlisle
  • 757,742
5

It's quite simple with alignat and the \mathrlap command from mathtools:

    \documentclass{article}
    \usepackage{mathtools}
\begin{document}

\begin{alignat*}{2}
 x &= a &&+ b (ert)\\
            & &&+ c(ert)\\
            &=\mathrlap{abc}
\end{alignat*}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Why a outside the \mathrlap? Just to be complicated? – egreg Jul 30 '22 at 06:50
  • @egreg: Not quite: I just thought that probably the $a$ s would not be well aligned and I didn't have time to test. This morning, I have more time and I could. You're right: there's no difference, and I'll fix it within seconds. Thank you for your comment! :o) – Bernard Jul 30 '22 at 07:53
  • What does the \mathrlap do here? In my real code I have a bunch more lines, would I need that for all following lines then? – Tom Jul 30 '22 at 14:24
  • @Tom; it places in math mode an expression and makes latex believe it has 0 width, so that it adds no horizontal space between the two alignment points. There exists also \mathlap, which is like the basic \llap, but in math mode. To make it fully clear , compare with the spacing you obtain without this command. – Bernard Jul 30 '22 at 15:47
4

Welcome to TeX.SX! You can probably use a \phantom here:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

[ \begin{aligned} x & = a + b (ert)\ & \phantom{{} = a} + c (ert)\ & = abc \end{aligned} ]

\end{document}

enter image description here

(In case you wonder why the {} are needed: The equals sign is a binary operator which, if it does not have a symbol before and after it, changes its spacing bahavior. See this answer about more on this.)