3

I am having trouble with the align environment. I wrote the following code almost works, but not quite:

\begin{align*}
\min_{x, y} \ &2x + 4y          &      & \min     \    &9x^2 + 2y  \\
\text{s.t.} \ &2x^2 - 4y \le 7  & \iff & \text{s.t.} \ &2x^2 - 4y \le 7 \\
              &3x+2y \ge 4      &      &               &3x+2y \ge 4  
\end{align*}

Output:

I like how the problem looks on the left side. But on the right, the spacing is wrong. How can I make the problem on the right look like the one on the left?

Thank you very much!

6
  • you are missing a & in every row before the second block so &&\min, &&\text , && Nov 17, 2022 at 8:59
  • 1
    @DavidCarlisle Thanks a lot. What is actually going on when you put & vs &&? From my understanding, when you make an align environment, the & are used to separate "columns". So it seems to me that && just makes an empty column.
    – user56202
    Nov 17, 2022 at 16:53
  • align columns are like an array with {rl@{\quad}rl@{\quad}rl...) you want to arrange each a&=b equation is in a rl pair so they align towards the =, You had got out of sync so a&=b aligned as l@{\quad}r so the equation is pulled apart. Nov 17, 2022 at 17:02
  • @DavidCarlisle So if you put A & B & C & D, LaTeX assumes that there is an equal sign between A, B and between C, D, i.e. you are trying to display A = B C = D?
    – user56202
    Nov 17, 2022 at 17:44
  • 1
    @DavidCarlisle Ah okay. I didn't know that aling assumes that some &'s are for equal signs, and some are to separate columns. I thought they all &'s separate columns. Thank you so much!
    – user56202
    Nov 17, 2022 at 17:56

1 Answer 1

3

Something like this?

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{amsmath}    % for 'alignat*' environment
\begin{document}
\begin{alignat*}{3}
\min_{x, y}\ &2x + 4y         &&                &        \min\ &9x^2 + 2y  \\
\text{s.t.}\ &2x^2 - 4y \le 7 &&\qquad\iff\qquad& \text{s.t.}\ &2x^2 - 4y \le 7 \\
             &3x+2y \ge 4     &&                &              &3x+2y \ge 4  
\end{alignat*}
\end{document}
2
  • Thank you very much. What is actually going on when you put & vs &&? From my understanding, when you make an align environment, the & are used to separate "columns". So it seems to me that && just makes an empty column.
    – user56202
    Nov 17, 2022 at 16:53
  • 1
    see my comment under the question re && @user56202 Nov 17, 2022 at 17:25

You must log in to answer this question.

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