# Writing an extremely simple linear program

I am trying to create a linear program

Similar to:

However the code just wouldn't align f(x) with the constraints

Can anyone help?

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{thmtools}

\setlength\parindent{0pt}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{plain}
\declaretheorem[name=Theorem, numberwithin=section]{thm}
\declaretheorem[name=Lemma, numberwithin=section]{lem}
\declaretheorem[name=Proposition, numberwithin=section]{prop}
\declaretheorem[name=Corollary, numberwithin=section]{cor}
\declaretheorem[name=Conjecture, numberwithin=section]{conj}
\declaretheorem[name=Claim, numberwithin=section]{claim}

\theoremstyle{remark}
\newtheorem{remark}{Remark}[section]
\newtheorem{example}{Example}[section]
\usepackage{hyperref}

\begin{document}

\section{Introduction}
\begin{equation*}
\begin{aligned}
& \text{maximize}
& f(x) \\
& \text{subject to}
&  x_1+x_2 = 8\\
& & x_3 + x_4 = 2
\end{aligned}
\end{equation*}

\bibliographystyle{plain}
\bibliography{references}
\end{document}


## 2 Answers

You can use alignat to define a number of Right-Left alignments:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\section{Introduction}

\begin{alignat}{2}
& \text{maximize}   & \quad & f(x)          \nonumber \\
& \text{subject to} &       & x_1 + x_2 = 8 \\
&                   &       & x_3 + x_4 = 2 \nonumber
\end{alignat}

\end{document}

• My triple PhD degree will never finish without you – Fraïssé Jan 24 '17 at 21:19

Each line of your aligned environment starts with &. Delete it and replace the remaining & on each line by &~.