# Align some equations in empheq environment

I am trying to align some equations in an empheq environment but cannot get it right. Here is my MWE:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{empheq}
\usepackage{amsfonts}

\newcommand{\integers}[2]{[\![#1,#2]\!]}

\begin{document}

Test 1:
\begin{empheq}{align}
&\max~w_1 \sum_{i,j} t_{ij}(1-x_{ij})+w_2 gl\sum_{i,j} \Big(4x_{ij}-\sum_{(p,q)\in A_{ij}} z_{ijpq}\Big)&&\\
& z_{ijpq} \leq y_i &\forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \leq y_j &\forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \geq y_i + y_j - 1 &\forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& x_{ij} \in \{0,1\}&\forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \in \{0,1\}&\forall i,p \in \integers{1}{m}, \forall j,q \in \integers{1}{n}
\end{empheq}

Test 2:

\begin{empheq}{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}

\end{document}


Test2 comes from the empheq documentation. Here are my two questions:

1. Test2 is aligned left, as expected, but Test1 is not. How can I align all left in Test1?

1. The first equation of Test1 being very long, I would like to ignore it in the align, and get something like this (the green lines show the alignment I am looking for):

I tried something which does not compile:

\begin{empheq}[left=(P_2)\empheqlbrace]
\max~w_1 \sum_{i,j} t_{ij}(1-x_{ij})+w_2 gl\sum_{i,j} x_{ij}\Big(4-\sum_{(p,q)\in A_{ij}} x_{pq}\Big)\\
\begin{align*}
& x_{ij} \in \{0,1\} &forall i \in \integers{1}{m}, j \in \integers{1}{n}
\end{align*}
\end{empheq}


I found this on StackExchange but I couldn't make it work with empheq.

• Why using empheq for this? – egreg Mar 18 '18 at 22:05
• I am using empheq because in fact I use it with [left=\empheqlbrace] option, since it is a system of equations. You're right to ask because I forgot to add this option in the MWE. – fidekild Mar 19 '18 at 10:33

with use of alignat=3 you can obtain:

edit as noted barbara beeton in her comment below (thank you very much!), if really want to left-align the column on the right, you should use &&:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{empheq}
\usepackage{amsfonts}

\newcommand{\integers}[2]{[\![#1,#2]\!]}

\begin{document}

Test 1:
\begin{empheq}{alignat=3} % <---
& \max~w_1 \sum_{i,j} t_{ij}(1-x_{ij})
&& + w_2 gl\sum_{i,j} \Big(4x_{ij}-\sum_{(p,q)\in A_{ij}} z_{ijpq}\Big)\\
& z_{ijpq} \leq y_i     &&   \forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \leq y_j     &&   \forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \geq y_i + y_j - 1
&&   \forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& x_{ij} \in \{0,1\}    &&   \forall i \in \integers{1}{m}, j \in \integers{1}{n}\\
& z_{ijpq} \in \{0,1\}  &&   \forall i,p \in \integers{1}{m}, \forall j,q \in \integers{1}{n}
\end{empheq}

Test 2:

\begin{empheq}{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{empheq}

\end{document}

• you really want to left-align the column on the right. (use &&) – barbara beeton Mar 18 '18 at 20:46
• @barbarabeeton, thank you very much! i corrected the answer. – Zarko Mar 18 '18 at 21:23
• @egreg, ups, + was on wrong side of ampersands :-(. now corrected. also helps your suggestion, of course. thank you very much! – Zarko Mar 18 '18 at 22:11
• Thank you very much, it's perfect! I don't really understand why it works though: since there are 3 columns, the third column (after the &&) should start at the end of the long first equation, no? – fidekild Mar 19 '18 at 10:37
• @fidekild, no. it start at anchor && which is before sign + after first term. – Zarko Mar 19 '18 at 11:38