# Aligning split equations to the left perfectly [duplicate]

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

The code below generates this equation:

whose split-equations are not 100% aligned.

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

\begin{document}

$$\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{document}


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{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{document}


Output:

• 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

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

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

\begin{document}

$$\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{document}

• 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

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.

\begin{document}

Text before the 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}
Text after the equation.

\end{document}


Output:

Here with stacks:

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

$$\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{document}


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

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

\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{document}