1

The problem

I have found that when I add a phantom{{}+{}} in an aligned environment, if this is followed by a summation symbol, the horizontal spacing is not the same as if I had actually used +.

Examples

enter image description here

If I vertically raise the lower symbol we can see that they are not vertically aligned.
enter image description here

However, they are aligned if I omit the + and the phantom
enter image description here

Why bother?

Because when I have a series of multi-line inequalities I don't like it when authors have the < symbols in line with multiple terms, but think it looks better when the first line is slightly indented (not required if a leading - is used). e.g.

enter image description here

MWE

\documentclass{extarticle}
\usepackage{amsmath,amssymb,physics}
\begin{document}
    \begin{align*}
        \mu(x, y) = & \phantom{{}+{}} \sum_{k=1}^{2K} \\ % \\[-3.55em]
                    & + \sum_{k=1}^{2K}
    \end{align*}
\end{document}
3

There are few points I want to clarify:

  1. The alignment tab & goes before the relation symbol, not after. You may take a look at one of my previous answers (shameless plug). If you follow this rule, then the use of \phantomrel (or other equivalences) is unavoidable.
  2. The reason that you get undesirable + behavior is partly due to the incorrect use of the alignment tab &. After the &, the immediate following + is prepended by an implicit {} and so it is interpreted as a binary operator “plus”. But you actually want it to be a unary operator “positive”, hence there will be spacing differences. According to your example, you actually want a binary “plus”.
  3. But since the + in & + \sum... is binary plus, why does it differ from & \phantom{{}+{}} \sum...? Well, although {}+{} produces a binary plus, the outer-layer \phantom{...} makes the whole thing into a \mathord. Note that \sum is a \mathop. Therefore, by rules, a thin space is used in the first line

    & \phantom{{}+{}} \sum... becomes {} <no space> mathord \, mathop

    while a median space is used in the second line

    & + \sum... becomes {} \: mathbin \: mathop

    so the spacing difference is expected.

With a combination of \phantomrel and \phantombin (together with a correct use of alignment tabs), this problem ceases to exist. Here is a MWE:

\documentclass{extarticle}
\usepackage{amsmath}
\newcommand\phantomrel[1]{\mathrel{\phantom{#1}}}
\newcommand\phantombin[1]{\mathbin{\phantom{#1}}}
\begin{document}
    \begin{align*}
        \mu(x, y) & =              {} \phantombin{+} \sum_{k=1}^{2K} \text{(Correct spacing)} \\ % \\[-3.55em]
                  & \phantomrel{=} {} +              \sum_{k=1}^{2K}
    \end{align*}
\end{document}

binary spacing

  • Can you avoid using the various phantomrel{=}. In the above example if I have several lines then this only requires a single phantom. – oliversm Sep 19 '18 at 15:49
  • @oliversm I have updated my answer to include additional explanations. :) – Ruixi Zhang Sep 19 '18 at 17:42
  • Thanks for highlighting the implicit {} at the start of the left aligned columns, and point (3). Also the shameless plug was well deserved, and I'll change my =& usage to &.... – oliversm Sep 20 '18 at 8:48
  • Sorry, but in the above example MWE you provide, are the empty {} just for clarity? (i.e. can they be removed?) – oliversm Sep 20 '18 at 8:53
  • 1
    @oliversm If you want a binary plus, then the {} cannot be removed. This is because & = + creates an “impossible” combination: There is “no way” for a binary operator to follow a relation operator (again, by TeX’s rules), and thus this binary plus will be converted into an ordinary object, hence a unary positive. So & = + is equivalent to {} mathrel mathord. By adding an explicit {}, now we have & = {} + becoming {} mathrel {} mathbin. See my other answer. – Ruixi Zhang Sep 20 '18 at 14:13
0

A \phantom doesn't inherit the math type of the object it replaces. So \phantom{=} does not behave as a relation.

Besides, =& is generally not needed, but it should be ={}& in case it becomes necessary.

However, there's a simpler solution.

Look, ma! No \phantom!

\documentclass{extarticle}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
\mu(x, y) &= & & \sum_{k=1}^{2K} \\
          &  &+& \sum_{k=1}^{2K}
\end{alignat*}

\end{document}

enter image description here

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.