I wrote the following text (you can find the code below).
I boxed my equations using the \boxed command. As you can see, because of the different text in front and behind the boxes, they are aligned pretty randomly (also the boxes are of different width, but that's not really evident from the picture). If all the boxes were in the same equation environment, I would know how to deal with that, but because they are seperated by text, I have no idea how to fix this.
I imagine an ideal solution to look something like this:
Primarily, I want the boxes to have their left edges aligned. It would be amazing, if also the width of the boxes could be adjusted to match.
Note: I do not want to give fixed values for where the boxes have to start, neither how large they are. I cannot estimate what space I will need in later equations.
I found this question and answer, but I am not sure whether minipages are a solution for my problem.
"Minimal" working example
This is the code with which I generates the text in my first picture.
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\begin{document}
\noindent
We so obtain the dual program
%
$$
\boxed{
\begin{array}{rl}
\min & \nu \\
\text{s.t.} & \mathrm{tr}(X) = 1 \\
& \langle X,\mathbf 1\rangle=0 \\
& \langle X,E^{ij}\rangle\le \nu,\quad\text{for all $ij\in E$}
\end{array}}\qquad \textcolor{lightgray}{(X\in\mathbf S^n_+,\nu \text{ free})}$$
%
By strong duality, we know that $\nu>0$ in the optimal point, and we can re-scale the problem by $X\mapsto X/\nu$.
%
$$
\boxed{
\begin{array}{rl}
\max & \mathrm{tr}(X) \\
\text{s.t.} & \langle X,\mathbf 1\rangle=0 \\
& \langle X,E^{ij}\rangle\le 1,\quad\text{for all $ij\in E$}
\end{array}}\qquad \textcolor{lightgray}{(X\in\mathbf S^n_+)}$$
%
The optimal value of this program is $1/a(G)$. We can again decompose $X$ into $ZZ^T$ with $Z=(z_1,...,z_n)$ to rewrite the program as
%
$$
\boxed{
\begin{array}{rl}
\max & \sum_{i=1}^n \| z_i\|^2 \\
\text{s.t.} & \sum_{i=0}^n z_i=0 \\
& \|z_i-z_j\|\le 1,\quad\text{for all $ij\in E$}
\end{array}}\qquad \textcolor{lightgray}{(z_i\in\mathbb R^n\text{ free})}$$
%
\end{document}



\( \)will give less obscure error messages when there is a mistake inside it. But they render the same though. – Andreas Storvik Strauman Mar 23 '18 at 19:51\mathllap. Sorry, I removed it quite inadvertently. As to including the page number into the tag, I didn't test it. However, you can use a second tag for boxes on the next page (choosing the correct tag has do be done by trial and error, in this case, of course). – Bernard Mar 24 '18 at 00:17