如何使整个页面上的方程式框架对齐?

如何使整个页面上的方程式框架对齐?

我写了下面的文字(您可以在下面找到代码)。

enter image description here

我使用命令将方程式框起来\boxed。如您所见,由于框前后的文本不同,它们的对齐方式相当随机(而且框的宽度也不同,但从图片上看不出来)。如果所有框都在同一个方程式环境中,我会知道如何处理,但由于它们被文本隔开,我不知道如何解决这个问题。

我想象的理想解决方案是这样的:

enter image description here

首先,我希望框的左边缘对齐。如果框的宽度也可以调整以匹配,那就太棒了。

笔记:我不想为框的起始位置给出固定值,也不想给出它们的大小。我无法估计在后面的方程中需要多少空间。

我发现问答,但我不确定小页面是否能解决我的问题。


“最小”工作示例

这是我用来生成第一张图片中的文本的代码。

\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}

答案1

解决方案是使用\eqframebox命令 from eqparbox,它向框命令添加一个标签,以便共享相同标签的所有框都具有这些框的最宽自然宽度。此外,我使用命令\mathrlapfrom 将注释标记为灰色 0 宽度mathtools。您不应该使用显示方程的plainTeX语法$$ ... $$,而应该使用 LaTeX 语法\[ ... \]::

\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} 

enter image description here

答案2

一种方法是让所有框的宽度固定,并让框与其他文本之间的偏移量固定。这里的想法是制作一个框架minipage,并固定其宽度。然后,您还可以固定vspace*{}左右的垂直距离( )。然后,您可以组合多个这样的框。我使用了您问题中的 TeX 并应用了它。

%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}

相关内容