2

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?

Wrong alignment

  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):

Targeted alignment

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.

2
  • 1
    Why using empheq for this?
    – egreg
    Commented Mar 18, 2018 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
    Commented Mar 19, 2018 at 10:33

1 Answer 1

4

with use of alignat=3 you can obtain:

enter image description here

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}

The very same result can be obtain without use of empheq environment:

\begin{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{alignat}

Test 2:
\begin{align}
a&=b\\
E&=mc^2 + \int_a^a x\, dx
\end{align}
8
  • 1
    you really want to left-align the column on the right. (use &&) Commented Mar 18, 2018 at 20:46
  • @barbarabeeton, thank you very much! i corrected the answer.
    – Zarko
    Commented Mar 18, 2018 at 21:23
  • @egreg, ups, + was on wrong side of ampersands :-(. now corrected. also helps your suggestion, of course. thank you very much!
    – Zarko
    Commented Mar 18, 2018 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
    Commented Mar 19, 2018 at 10:37
  • 1
    @JoãoBravo, of course, however, OP use empheq in her/his MWE, so I left it. I will add comment to my answer asap.
    – Zarko
    Commented Jan 21, 2020 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .