0

I want to align an equation at two places, and I have a code segment that looks like this:

\documentclass[a4paper]{paper}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\begin{document}

\begin{alignat*}{2}
g_P^x &= 3x_P^2 + a, \quad g_P^y &&= -2y_P, \\
v_P &= 2g_P^x, \quad u_P &&= (g_P^y)^2, \\
v &= \sum_{P \in G^+} v_P, \quad w &&= \sum_{P \in G^+} u_P + x_Pv_P.
\end{alignat*}

\end{document}

And this works to a certain extend, but there is a big gap between u_P and the equal sign. How can I get it closer to the equal sign so it is aligned with the stuff above and below it?

  • Why &&? Try putting the extra & before g_P, u_P, and w. – Phelype Oleinik Mar 10 '18 at 19:00
  • Because I thought, the first alignment point should be specified with & and the second one with &&. Can you write as answer, what you mean? – pixel Mar 10 '18 at 19:01
  • No, each & is an alignment point, just like in tables. Put an & before g_P, u_P, and w to align them too. – Phelype Oleinik Mar 10 '18 at 19:03
  • @PhelypeOleinik: I don't interpret &s like that: the first one introduces a new column of alignment,, and the second one marks the alignment point inside this column. – Bernard Mar 10 '18 at 19:06
  • @Bernard Hmmm... I didn't know that. Looking at your answer, it makes total sense. +1 :) – Phelype Oleinik Mar 10 '18 at 19:30
4

You must understand that in an align(at) environment with multiple alignment points, each even order & introduces a new column of alignment, and each odd order & marks the alignment point inside its column . That's why n alignment points require 2n-1 &s.

Applying this rule, and using the \smashoperator command from mathtools to improve the layout of big operators with wide sub/superscripts, you get this code (note you need only one \qquad in a well-chosen row):

\documentclass[a4paper]{paper}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
g_P^x &= 3x_P^2 + a, &\qquad g_P^y&= -2y_P, \\
v_P &= 2g_P^x, & u_P &= (g_P^y)^2, \\
v &= \smashoperator{\sum_{P \in G^+}} v_P, & w&= \smashoperator{\sum_{P \in G^+}} u_P + x_Pv_P.
\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.