4

I have the following MWE, showing how the two plus-signs of the second equation are not completely aligned with each other:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
f_\beta &= f_\beta \\
f_\beta &= + (-\Omega_{f_\beta})|_{(r, q)} \\
        &\phantom{{}=} + (-\Omega_{f_\beta})|_{(r, q)} \notag \\
\end{align}

\end{document}

I am using \phantom{{}=}, what else is needed to make the alignment correct for the +-signs, while keeping the alignment of the =-signs as well?

BillyJean
  • 1,743
  • 2
    use = {} & in the first row, and just & in the second. Basically you are align on the right of a relation, in which case care is needed to get = to use the correct spacing – daleif Apr 08 '16 at 16:00
  • @daleif Thanks for the swift reply. I updated my question to account for a more general case, where the current phantom-approach is better. Using your method wont align the =-signs – BillyJean Apr 08 '16 at 16:05
  • 1
    If you want to align on the + symbols, use &+ instead of &=. – Mico Apr 08 '16 at 16:06
  • 1
    I'd still go with @daleif's approach: use ={}& in the first two lines, and just & in the third one. – campa Apr 08 '16 at 16:09

2 Answers2

4

In the third line you have, after the alignment point,

{} \phantom{{}=} + (

(the first is automatically inserted) that makes four atoms

Ord Ord Bin Open

so this inserts spaces as

Ord (zero) Ord (\medmuskip) Bin (\medmuskip) Open

In the second line you have, instead

{} = + (

that produces the list of atoms

Ord Rel Bin Open

but the third atom doesn't make sense as a Bin, so it becomes Ord and the spacing is

Ord (\thickmuskip) Rel (\thickmuskip) Ord (zero) Open

Note that in the phantom you have “Ord (\thickmuskip) Rel” so this should explain the misalignments. In particular, the space between + and ( in the third line, that's not present in the second line.

Solution: a better phantom, with {} on either side, but embedded in a \mathopen, so the + will turn into an Ord like in the second line.

\documentclass{article}

\usepackage{amsmath}

\newcommand{\fakeeq}{\mathopen{\hphantom{{}={}}}}

\begin{document}

\begin{align}
f_\beta &= f_\beta \\
f_\beta &= + (-\Omega_{f_\beta})|_{(r, q)} \\
        &\fakeeq + (-\Omega_{f_\beta})|_{(r, q)} \notag
\end{align}

\end{document}

enter image description here

Alternatively, don't make TeX into considering + as a unary symbol:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
f_\beta ={}& f_\beta \\
f_\beta ={}& + (-\Omega_{f_\beta})|_{(r, q)} \\
           & + (-\Omega_{f_\beta})|_{(r, q)} \notag
\end{align}

\end{document}

enter image description here

In this case you may want to remove the \medmuskip on the left side of +:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
f_\beta ={}& f_\beta \\
f_\beta ={}& \mspace{-\medmuskip} + (-\Omega_{f_\beta})|_{(r, q)} \\
           & \mspace{-\medmuskip} + (-\Omega_{f_\beta})|_{(r, q)} \notag
\end{align}

\end{document}

enter image description here

For a review of the spacing rules, see What's the right space to right the alignment of a right aligned align environment?

egreg
  • 1,121,712
  • 1
    I know the spacing rules from the TeXBook and I regularly forget them: do you happen to know whether they are explained or summarized somewhere here on the site? If a question/answer deals with them it would be nice to link answers like yours. – campa Apr 08 '16 at 16:34
  • 1
    @campa This answer http://tex.stackexchange.com/a/81777/4427 perhaps? – egreg Apr 08 '16 at 16:36
  • Precisely! Thx. – campa Apr 08 '16 at 16:37
2

You could nest an aligned environment inside the align environment. In the "outer" align environment, perform alignment on the = symbols. In the "inner" aligned environment, perform alignment on the + symbols.

enter image description here

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

\begin{align}
f_\beta &= f_\beta \\
f_\beta &= \!\begin{aligned}[t]
             &+ (-\Omega_{f_\beta})|_{(r, q)} \\
             &+ (-\Omega_{f_\beta})|_{(r, q)}
           \end{aligned}
\end{align}

\end{document}

Addendum: If the + symbols should be treated as unary rather than as binary operators, it suffices to encase them in curly braces (which converts their status to mathord). TeX has different spacing rules for - and + depending on whether they are unary or binary operators.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
f_\beta &= f_\beta \\
f_\beta &= \!\begin{aligned}[t]
             &{+} (-\Omega_{f_\beta})|_{(r, q)} \\
             &{+} (-\Omega_{f_\beta})|_{(r, q)}
           \end{aligned}
\end{align}
\end{document}
Mico
  • 506,678