# How to split a long constraint in this optimization problem?

I have an optimization problem that has a long constraint. So, I would like to split it. Obviously, I search how to split long equation but I did not find my answer as the problem is related to how I format my optimization problem. Especially, I write it based on the answer here of my previous question. Below I give the code:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}

\newcommand{\maximize}{%
\mathopen{}\operatorname*{maximize}%
}
\newcommand{\subjto}{\textup{subject to}}

\newcounter{problem}
\newcounter{save@equation}
\newcounter{save@problem}

\makeatletter
\newenvironment{problem}
{\setcounter{problem}{\value{save@problem}}%
\setcounter{save@equation}{\value{equation}}%
\let\c@equation\c@problem
\renewcommand{\theequation}{P\arabic{equation}}%
\subequations
}
{\endsubequations
\setcounter{save@problem}{\value{equation}}%
\setcounter{equation}{\value{save@equation}}%
}

\begin{document}

\begin{problem}\label{pb:2}
\begin{alignat}{2}
& \maximize_{\mathbf{x}}
& \text{subject to}
& &  \sum_{i=1}^nw_ix_{i}\leqslant W,\label{c:1}\\
& & & \left(c_1+c_2+\ldots+c_n\right)x_ix_j\leqslant C,\forall i\in\{1,\ldots,n\}, j\in\{1,\ldots,n\},\label{c:2}\\
& & & x_{ i }\in\{0, 1\}, \forall i=1\ldots,n.\label{c:3}
\end{alignat}
\end{problem}

\end{document}


which produces the following: Now, constraint (P1c) is long (as I actually work with double column paper). I would like to split it just after C,. I am asking how to split it according to my code? Should I change the alignat to split or something?

I tried to do it with:

1. \\. Here I am getting something ugly, like:

& & & \left(c_1+c_2+\ldots+c_n\right)x_ix_j\leqslant C,\\ \forall i\in\{1,\ldots,n\}, j\in\{1,\ldots,n\},\label{c:2}\\ 2. \\ & & & and \quad. Here it is better but still not enough, like:

& & & \left(c_1+c_2+\ldots+c_n\right)x_ix_j\leqslant C,\\ & & &\quad\quad\quad\quad \forall i\in\{1,\ldots,n\}, j\in\{1,\ldots,n\},\label{c:2}\\ But this won't work as I add more \quad.

Thanks.

• It's unfortunate that people don't upvote well-rounded questions like this. – Werner Jan 11 '17 at 18:25

Here is a solution, if I've well understood what you want:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{newtxtext,newtxmath}

\newcommand{\maximize}{%
\mathopen{}\operatorname*{maximize}%
}
\newcommand{\subjto}{\textup{subject to}}

\newcounter{problem}
\newcounter{save@equation}
\newcounter{save@problem}

\makeatletter
\newenvironment{problem}
{\setcounter{problem}{\value{save@problem}}%
\setcounter{save@equation}{\value{equation}}%
\let\c@equation\c@problem
\renewcommand{\theequation}{P\arabic{equation}}%
\subequations
}
{\endsubequations
\setcounter{save@problem}{\value{equation}}%
\setcounter{equation}{\value{save@equation}}%
}

\begin{document}

\begin{problem}\label{pb:2}
\begin{alignat}{2}
& \maximize_{\mathbf{x}}
& \text{subject to}
& & \sum_{i=1}^nw_ix_{i}\leqslant W,\label{c:1}\\
& & &\!\begin{aligned} (c_1 +c_2 +\dots+c_n&)x_ix_j\leqslant C,\\ & \forall i\in\{1,\ldots,n\}, j\in\{1,\ldots,n\},
\end{aligned}\label{c:2}\\
& & & x_{ i }\in\{0, 1\},\; \forall i=1\ldots,n.\label{c:3}
\end{alignat}
\end{problem}

\end{document} • Can I shift (P1c) (the second part of (P1c)) to the right more? – Ribz Jan 11 '17 at 17:33
• Oh! yes, very easily: move the & at the line above a little more to the right. See my updated answer: I now have &). – Bernard Jan 11 '17 at 17:47