7

Is there a cleaner way to align all equations to the left?

The code below generates this equation:

enter image description here

whose split-equations are not 100% aligned.

\documentclass{article}
\usepackage{amsmath}
\usepackage{breqn}

\begin{document}

\begin{equation}
\begin{split}
&\text{minimize \quad} Z(w) \\
&\text{subject to\quad }     f_1(w) \leq a_1\\
&\quad \quad \quad \quad \quad   f_2(w) \leq a_2 \\
&\quad \quad \quad \quad \quad \quad \quad \vdots\\
&\quad \quad \quad \quad \quad   f_m(w) \leq a_m,
\end{split}
\end{equation}


\end{document}
6

This solution uses array. Like tabular, it adds a fixed space between columns. Just for fun, I also lined up the inequalities.

\documentclass{article}
\usepackage{mathtools}%for \vdotswithin
\usepackage{breqn}% I have no idea what this does

\begin{document}

\begin{equation}
\begin{array}{ll@{}l}
\text{minimize} &Z(w)\\
\text{subject to} &f_1(w) &{}\leq a_1\\
& f_2(w) &{}\leq a_2 \\
&&\vdotswithin{\leq} \\
&f_m(w) &{}\leq a_m,\\
\end{array}
\end{equation}

\end{document}

Output:

Output of the code

| improve this answer | |
  • 1
    Actually, I prefer this solution to mine. If I can suggest an improvement, I’d use the >{} feature of the array package to automatically inject the empty subformula in the third column. – GuM May 25 '18 at 1:10
  • @GuM - Good point. Of course it would also require the array package and should be >{{}}. – John Kormylo May 25 '18 at 13:28
4

Just make it simple, the & is your friend here, move the text to other side.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{breqn}

\begin{document}

\begin{equation}
\begin{split}
\text{minimize \quad}&Z(w) \\
\text{subject to\quad }&f_1(w) \leq a_1\\
&f_2(w) \leq a_2 \\
&\quad\quad \vdots\\
&f_m(w) \leq a_m,
\end{split}
\end{equation}


\end{document}
| improve this answer | |
  • 1
    I too had thought of something like this, but the OP seems to want the words “minimize” and “subject” to be left-aligned as well. – GuM May 25 '18 at 1:12
  • Yeah, maybe. It was not so clear for me, since he/she says equations and draw only to the right part... dunno. – G. Bay May 25 '18 at 1:23
4

Here is a possible solution:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools} % also loads amsmath



\begin{document}

Text before the equation
\begin{equation}
    \begin{alignedat}{2}
        & \text{Minimize } && Z(w) \\
        & \text{subject to } && f_{1}(w)\le a_{1} \\
        & && f_{2}(w)\le a_{2} \\
        & && \hphantom{f_{2}(w)}\vdotswithin{\le} \\
        & && f_{m}(w)\le a_{m} \\
    \end{alignedat}
    \label{eq:minimize}
\end{equation}
Text after the equation.

\end{document}

Output:

Output of the code

| improve this answer | |
4

Here with stacks:

\documentclass{article}
\usepackage{mathtools}%for \vdotswithin
\usepackage{tabstackengine}%
\setstackgap{L}{14pt}
\begin{document}

\begin{equation}
\stackText
\Longunderstack[l]{minimize\\subject to}
\quad\stackMath
\TABbinary
\tabbedLongunderstack[l]{
Z(w)&\\
f_1(w) &\leq a_1\\
f_2(w) &\leq a_2 \\
&\vdotswithin{\leq} \\
f_m(w) &\leq a_m,
}
\end{equation}

\end{document}

enter image description here

...and here's one not all aligned to the left:

\documentclass{article}
\usepackage{mathtools}%for \vdotswithin
\usepackage{tabstackengine}%
\setstackgap{L}{14pt}
\begin{document}

\begin{equation}
\stackText
\Longunderstack[l]{minimize\\subject to}
\quad\stackMath
\alignLongunderstack{
Z(w)\phantom{{}\le{}}&\\
f_1(w) \leq& a_1\\
f_2(w) \leq& a_2 \\
\vdotswithin{\leq}& \\
f_m(w) \leq& a_m,
}
\end{equation}

\end{document}

enter image description here

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.