6

The second alignat below illustrates my problem.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
  a &= & b \\
    &  & + c
\end{alignat*}
\begin{alignat*}{2}
  a &= & b \\
    &  & + c \\
    &= \text{long expression}
\end{alignat*}
\end{document}

I want the third line of the equation not to alter spacing on previous lines. In other words, I want a math environment that behaves similarly to the tabbing environment. Could somebody help?

Edit: The example I show above is a simplified one. In my real problem, the part corresponding to = b is quite complicated. If we use Werner's solution below, we would be repeating the whole complicated expression in \phantom{}. So, I guess there is no ready-made tabbing-like environment?

My current workaround is to use \hspace*{} in place of \phantom{}, manually adjusting the position. (I'm not claiming it is better. Manual adjustment is annoying.)

Edit 2: Werner has made me realize that I simplified my code so much that a simple \phantom{{}={}} is a good solution to the simplified code. So, the example below is a more accurate illustration of my original problem:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  a &= b [ c + d \\
    &\phantom{{}=b [ c} + e] \\
    &= \text{long expression}
\end{align*}
\end{document}

In this case, (I think) we have to repeat part of the previous line in \phantom, which is annoying when b and c are complicated. As I said in my "Edit" above, I'm currently using \hspace* to avoid repeating the complicated expression in a phantom.

  • 1
    alignat is really the wrong environment to use here, and the use of & after the = is defensible only in very special circumstances. the align example in @Werner's answer is a much better approach. i recommend referring to the amsmath manual (texdoc amsmath) -- it isn't really very long. – barbara beeton Jan 16 '14 at 17:17
6

There are a myriad of ways you can achieve this alignment. Here are just two:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{alignat*}{2}
  a &={} && b \\
    &    && + c
\end{alignat*}

\begin{align*}
  a &= b \\
    &\phantom{{}={}} + c \\
    &= \text{long expression}
\end{align*}
\end{document}
  • Thanks for the answer! (And thanks for migrating my posting to this place. I'm totally new here.) So, that means that there isn't a simple solution, I guess. In my example, the "= b" part is quite simple, but in my real problem that part is quite complicated. That probably means that I have to repeat the whole expression in \phantom{} . . . – Ryo Jan 16 '14 at 21:16
  • @Ryo: No, the \phantom is just to have +c start (horizontally) at the same position as b (barring the regular spacing associated with binary relations like +. You can use either of the methods I propose above. – Werner Jan 16 '14 at 21:20
  • In this particular case, yes, you are right. After all, I've realized I simplified my code so much that your solution does work for the simplified case. That was my fault. I'll further edit my original post so that you understand the problem. Thanks! – Ryo Jan 17 '14 at 23:47
3

To get the third line to not affect the spacing of the first two you can use \rlap{\text{long expression}} and thus no need to change anything before that line:

enter image description here

Note:

  • I also added a curly brace pair as in the {}+c so that the + is treated as a binary operator.

Code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
  a &= & b \\
    &  & {}+ c
\end{alignat*}
\begin{alignat*}{2}
  a &= & b \\
    &  & {}+ c \\
    &= \rlap{\text{long expression}}
\end{alignat*}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.