2

I'm trying to typeset an optimization problem that uses variable conditioned constraints (vif) in combination with normal constraints. My current syntax (of a part of the problem) is

\begin{align*}
\max \sum_{i \in I} z_i \\
\text{subject to} \\
 x_i^0 &= x_i^{\text{start}}  &&\forall i \in I, \\
 l_i^t + r_i^t + c_i^t &= 1  &&\forall t = 0,...,N-1, i \in I, \\
\text{vif } v_i^t = 1 \text{ then} \\
 x_j^t - x_i^t &\leq \epsilon \\
\text{else} \\
 x_j^t - x_i^t &\geq \epsilon + \hat{\epsilon}\\
\text{end} &&&\forall t=0,...,N-1, i,j \in I: i < j, \\
 k_i^t &= \sum_{j \in I \setminus \{i\}} v_{\min(i,j),max(i,j)}+1+c_i^t  &&\forall t=0,...,N-1, i \in I, \\
\end{align*}

which displays misplaced end and else

I would like to have the else and the end aligned to the left (like the vif is already) while maintaining the slight indent for the line underneath the vif. If I try to put an ampersand in front of the else or end however, I cannot manage to align the other equations around the = or \geq signs properly. A satisfactory result would look roughly like this (I edited the picture) edited picture

How can such indentation be achieved while keeping the constraints aligned in this way?

New contributor
ChocolateBar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3

One quick fix is to make the two lines for if and else have the same width as that for the line \text{vif } v_i^t = 1 \text{ then}. You can use makebox for this. calc package is also required to allow \widthof to calculate the width automatically.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{calc}    
\begin{document}

\newcommand{\adjleft}[1]{\makebox[\widthof{$\text{vif } v_i^t = 1 \text{ then}$}][l]{#1}}

\begin{align*}
\max \sum_{i \in I} z_i \\
\text{subject to} \\
 x_i^0 &= x_i^{\text{start}}  &&\forall i \in I, \\
 l_i^t + r_i^t + c_i^t &= 1  &&\forall t = 0,...,N-1, i \in I, \\
\text{vif } v_i^t = 1 \text{ then} \\
 x_j^t - x_i^t &\leq \epsilon \\
\adjleft{else}  \\
 x_j^t - x_i^t &\geq \epsilon + \hat{\epsilon}\\
\adjleft{end} &&&\forall t=0,...,N-1, i,j \in I: i < j, \\
 k_i^t &= \sum_{j \in I \setminus \{i\}} v_{\min(i,j),max(i,j)}+1+c_i^t  &&\forall t=0,...,N-1, i \in I, \\
\end{align*}

\end{document}

enter image description here

Your Answer

ChocolateBar is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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