# How to align framed equations over the whole page?

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}


A solution with the \eqframebox command, from eqparbox, which adds a tag to the box commands, so that all boxes sharing the same tag have the width og the widest natural width of these boxes. In addition I mage the comments in grey 0 width with the \mathrlap command, from mathtools. Not you should not use the plainTeX syntax $$...$$ for displayed equations, but the LaTeX syntax: $...$:

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{amssymb}
\DeclareMathOperator{\tr}{tr}

\usepackage{eqparbox}

\usepackage{xcolor}

\begin{document}

\noindent
We so obtain the dual program
%
$\eqframebox[FrEq]{  \begin{array}{rl} \min & \nu \\ \text{s.t.} & \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 \mathrlap{\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$.
%
$\eqframebox[FrEq]{  \begin{array}{rl} \max & \mathrm{tr}(X) \\[0.5ex] \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 \mathrlap{\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
%
$\eqframebox[FrEq]{  \begin{array}{rl} \max & \sum_{i=1}^n \| z_i\|^2 \\[1ex] \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 \mathrlap{\textcolor{lightgray}{(z_i\in\mathbb R^n\text{ free})}}$

\end{document}


• Shouldn't you also use the LaTeX-inline syntax? ( ) instead of ? :) – Andreas Storvik Strauman Mar 23 '18 at 19:44
• Why? I don't think it implies whatever as to spacing. The problem with $$...$$ is vertical spacing. – Bernard Mar 23 '18 at 19:47
• It says here that  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
• This looks very promising. Unfortunately, I will not have the chance to try it out until next week. But I have some questions: is it possible to match only boxes which are on the same page, e.g. by including the page number into the box-tag? Furthermore, you removed the text in front of the last box. I assume that this is also no problem by just using \mathllap, right? – M. Winter Mar 23 '18 at 23:47
• Yes, you can use \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 0:17

One way would be to make all boxes fixed width and fixed offset between the boxes and your other text. Idea here is to make a framed minipage, and fix the width of it. Then you can also fix the vertical distance (vspace*{})) from left and right. You then combine multiple of these boxes. I used the TeX from your question and applied it.

%Space in front
\hspace*{1em}
%Minipage to contain text in front
\begin{minipage}{0.2\textwidth}
TEXTINFRONT
\end{minipage}%
%Space between front-text and maths
\hspace*{1em}
% Frame maths-box
\fbox{
\begin{minipage}{0.5\textwidth}
$\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}$
\end{minipage}%
}%
%Space between maths-box and right text
\hspace*{1em}
%Right text
\begin{minipage}{0.2\textwidth}
$$\displaystyle \qquad \textcolor{lightgray}{(X\in\mathbf S^n_+,\nu \text{ free})}$$
\end{minipage}