3

I am trying to create a linear program

Similar to:

enter image description here

However the code just wouldn't align f(x) with the constraints enter image description here

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

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

enter image description here

\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}
1
  • My triple PhD degree will never finish without you – Fraïssé Jan 24 '17 at 21:19
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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