I found here a possibility for stating linear programs. But if I have several LPs and change for example one of the constraints, the positions of the captions get lost - only the last of them is correct. Is it possible to fix it? Or even better: how can I write the caption next to the LP (just like for the first LP in the picture)?
Here's my code:
\documentclass{scrbook}
\usepackage{mathtools,zref-savepos}
\parindent0mm
\begin{document}
\zsavepos{text-left-margin}%
Heres is some text.
\begin{alignat*}{4}
& \zsavepos{top-lp}\text{min} \quad \mathrlap{\sum_{a \in A} k_a u_a + \sum_{r \in R} \sum_{a \in A} f_a^r y_a^r} \\
& \text{s.t.} \quad & \smashoperator{\sum_{a \in \delta_i^+}} y_a^r - \smashoperator{\sum_{a \in \delta_i^-}} y_a^r
&= t & \quad & (\forall r \in R)(\forall i \in V) \\
& & y_a^r &\leq u_a && (\forall r \in R)(\forall a \in A) \\
& & u_a &\in \{0,1\} && (\forall a \in A) \\
& & y_a^r &\in [0,1] && (\forall r \in R)(\forall a \in A)\zsavepos{bottom-lp}
\raisebox{0.5\dimexpr\zposy{top-lp}sp-\zposy{bottom-lp}sp}[0pt][0pt]{%
\makebox[0pt][r]{\rlap{(LP)}\hspace*{\dimexpr\zposx{bottom-lp}sp-\zposx{text-left-margin}sp}}}
\end{alignat*}
Text...
\begin{alignat*}{4}
& \zsavepos{top-lp}\text{min} \quad \mathrlap{\sum_{a \in A} k_a u_a + \sum_{r \in R} \sum_{a \in A} f_a^r y_a^r} \\
& \text{s.t.} \quad & \smashoperator{\sum_{a \in \delta_i^+}} y_a^r - \smashoperator{\sum_{a \in \delta_i^-}} y_a^r
&= t & \quad & (\forall r \in R) \\
& & y_a^r &\leq u_a && (\forall r \in R) \\
& & u_a &\in \{0,1\} && (\forall a \in A) \\
& & y_a^r &\in [0,1] && (\forall r \in R)\zsavepos{bottom-lp}
\raisebox{0.5\dimexpr\zposy{top-lp}sp-\zposy{bottom-lp}sp}[0pt][0pt]{%
\makebox[0pt][r]{\rlap{(LP)}\hspace*{\dimexpr\zposx{bottom-lp}sp-\zposx{text-left-margin}sp}}}
\end{alignat*}
Text...
\begin{alignat*}{4}
& \zsavepos{top-lp}\text{min} \quad \mathrlap{\sum_{a \in A} k_a u_a + \sum_{r \in R} \sum_{a \in A} f_a^r y_a^r} \\
& \text{s.t.} \quad & \smashoperator{\sum_{a \in \delta_i^+}} y_a^r - \smashoperator{\sum_{a \in \delta_i^-}} y_a^r
&= abc & \quad & \\
& & y_a^r &\leq u_a && a \in A\\
& & u_a &\in \{0,1\} && \\
& & y_a^r &\in [0,1] && \zsavepos{bottom-lp}
\raisebox{0.5\dimexpr\zposy{top-lp}sp-\zposy{bottom-lp}sp}[0pt][0pt]{%
\makebox[0pt][r]{\rlap{(LP)}\hspace*{\dimexpr\zposx{bottom-lp}sp-\zposx{text-left-margin}sp}}}
\end{alignat*}
\end{document}
And this is the result:


text-left-marginlabel is set on a specific page, and gives a way to identify the left-most margin of that page. If your class issues atwo-sideoption, then it may be that you have a different left/right margin depending on whether you're on an even/odd page. Based on that you may have to create a separatetext-left-margin-evenandtext-left-margin-oddmarker, and use the appropriate one for that page. – Werner Dec 07 '15 at 21:19