我在使用投影幻灯片时遇到了问题。我尝试解决过几个问题。
- 如何正确缩放方程式
- 如何将四个限制对齐到同一高度
- 如何写两条带有变量的垂直线,如附图所示。
感谢您的任何想法!
\documentclass{beamer}
\usetheme{CambridgeUS}
\begin{document}
\begin{frame}{Primal-dual}
\begin{columns}[T]
\begin{column}{.5\textwidth}
\small
\[
\text{Min} \sum_{i=1}^{m+1}\sum_{j=1}^{n+1}c_{ij}x_{ij}
\]
\[\scalebox{0.8}{%
$
\hskip4.5em \text{s.a.} \quad
\begin{aligned}[t]
&\sum_{j=1}^{n}x_{ij}-x_{i,n+1}= a_i \qquad \forall i=1,\hdots,m\\
& \textcolor{blue}{\sum_{j=1}^{n}}x_{m+1,j}+\textcolor{magenta}{x_{m+1,n+1}}=a_{m+1}\\
&\sum_{i=1}^{m}x_{ij}+x_{m+1,j}= b_j \qquad \forall j=1,\hdots,n\\
&-\textcolor{red}{\sum_{i=1}^{m}}x_{i,n+1}+\textcolor{magenta}{x_{m+1,n+1}}=b_{n+1}\\
&x_{ij}\ge 0 \qquad
\left\{
\begin{aligned}
\forall i=&1,\hdots,m\\ \forall j=&1,\hdots,n\\
\end{aligned}
\right.
\end{aligned}
$}
\]
\normalsize
\end{column}
\hfill%
\begin{column}{.5\textwidth}
\small
\[
\text{Max} \sum_{i=1}^{m+1}u_i a_i+\sum_{j=1}^{n+1}v_j b_j
\]
\[\scalebox{0.8}{%
$
\hskip5em \text{s.a.} \quad
\begin{aligned}[t]
& u_i+v_j \le c_{ij}\\
& \\
& -u_i-v_{n+1} \le c_{i,n+1}\\
& \\
& u_{m+1}+v_j \le c_{m+1,j}\\
& \\
& u_{m+1}+v_{n+1} \le c_{{m+1},{n+1}}\\
\end{aligned}
$}
\]
\normalsize
\end{column}
\end{columns}
\end{frame}
\end{document}
答案1
这个想法与 Werner 的使用想法相同array
,但有一些小细节(以及您在答案中展示的颜色)。
\documentclass{beamer}
\usetheme{CambridgeUS}
\usepackage{mathtools,array}
\DeclareMathOperator{\Min}{Min}
\DeclareMathOperator{\Max}{Max}
\newcommand{\nominus}{\mathllap{-}}
\begin{document}
\begin{frame}{Primal-dual}
\scriptsize
\begin{equation*}
\renewcommand{\arraystretch}{2}
\begin{array}{
@{}
>{$}c<{$} % s.a.
>{\displaystyle}l % main column 1
|@{\,} % vertical line
>{\displaystyle}c % middle column
@{\,}| % vertical line
>{$}c<{$} % s.a.
>{\displaystyle}l % main column 2
@{}
}
\multicolumn{2}{@{}>{\displaystyle}l}{
\! \Min \sum_{i=1}^{m+1} \sum_{j=1}^{n+1}c_{ij}x_{ij}
}
&
\multicolumn{1}{c}{} % no vertical rule here
&
\multicolumn{2}{>{\displaystyle}l}{
\! \Max \sum_{i=1}^{m+1}u_i a_i+\sum_{j=1}^{n+1}v_j b_j
}
\\
% first row
s.a. &
\sum_{j=1}^{n}x_{ij}-x_{i,n+1}= a_i \qquad\hfill \forall i=1,\hdots,m &
u_i &
s.a. &
u_i+v_j \le c_{ij}
\\
% second row
&
\mathop{\textcolor{blue}{\sum_{j=1}^{n}}}x_{m+1,j}+\textcolor{magenta}{x_{m+1,n+1}}=a_{m+1} &
u_{m+1} &
&
\nominus u_i-v_{n+1} \le c_{i,n+1}
\\
% third row
&
\sum_{i=1}^{m}x_{ij}+x_{m+1,j}= b_j \qquad\hfill \forall j=1,\hdots,n &
v_j &
&
u_{m+1}+v_j \le c_{m+1,j}
\\
% fourth row
&
\nominus\!\mathop{\textcolor{red}{\sum_{i=1}^{m}}}x_{i,n+1}
+\textcolor{magenta}{x_{m+1,n+1}}=b_{n+1} &
v_{n+1} &
&
u_{m+1}+v_{n+1} \le c_{{m+1},{n+1}}
\\
% fifth row
&
\multicolumn{1}{l}{
x_{ij}\ge 0 \qquad
\left\{
\begin{aligned}
\forall i&=1,\dots,m\\
\forall j&=1,\dots,n
\end{aligned}
\right.
}
\end{array}
\end{equation*}
\end{frame}
\end{document}
\nominus
左侧附加一个减号,但我们需要修复彩色总和旁边的间距。这些命令\multicolumn
会覆盖默认对齐。
我们\qquad\hfill
确保“所有”符号前的间距,以及条件的右对齐。
请注意,\scriptsize
必须要走出equation*
环境。
答案2
由于有许多对齐和垂直规则,我使用以下方式设置array
:
\documentclass{beamer}
\usepackage{amsmath,array,graphicx}
\begin{document}
\begin{frame}
\resizebox{\linewidth}{!}{$
\renewcommand{\arraystretch}{2}
\begin{array}{ r >{\displaystyle}l | c | r @{} >{{}}l }
& \multicolumn{1}{c}{\displaystyle
\min \sum_{i = 1}^{m + 1} \sum_{j = 1}^{n + 1} c_{ij} x_{ij}
} & \multicolumn{1}{c}{
\renewcommand{\arraystretch}{1}\begin{tabular}{@{} c @{}}
variable \\ dual
\end{tabular}} & \multicolumn{2}{c}{\displaystyle
\max \sum_{i = 1}^{m + 1} u_i a_i + \sum_{j = 1}^{n + 1} v_j b_j
} \\
\text{s.t.} &
\sum_{j = 1}^n x_{ij} - x_{i, n + 1} = a \quad \forall i = 1, \dotsc, m &
u_i &
u_i + v_j &\leq c_{ij} \\
& \sum_{j = 1}^n x_{m + 1, j} + x_{m + 1, n + 1} = a_{m + 1} &
u_{m + 1} &
-u_i - v_{n + 1} &\leq c_{i, n + 1} \\
& \sum_{i = 1}^m x_{ij} + x_{m + 1, j} = b_j \quad \forall j = 1, \dotsc, n &
v_j &
u_{m + 1} + v_j &\leq c_{m + 1, j} \\
& -\sum_{i = 1}^m x_{i, n + 1} + x_{m + 1, n + 1} = b_{n + 1} &
v_{n + 1} &
u_{m + 1} + v_{n + 1} &\leq c_{m + 1, n + 1} \\
& \multicolumn{2}{l}{
\renewcommand{\arraystretch}{1.5}
x_{ij} \geq 0 \quad \left\{ \begin{array}{@{} l @{}}
\forall i = 1, \dotsc, m \\
\forall j = 1, \dotsc, n
\end{array}\right.
}
\end{array}
$}
\end{frame}
\end{document}
如果您希望对左侧列进行一些额外的对齐,可以选择以下选项:
\documentclass{beamer}
\usepackage{amsmath,array,graphicx}
\begin{document}
\begin{frame}
\resizebox{\linewidth}{!}{$
\renewcommand{\arraystretch}{2}
\begin{array}{ r >{\displaystyle}r @{} >{{}}l | c | r @{} >{{}}l }
& \multicolumn{2}{c}{\displaystyle
\min \sum_{i = 1}^{m + 1} \sum_{j = 1}^{n + 1} c_{ij} x_{ij}
} & \multicolumn{1}{c}{
\renewcommand{\arraystretch}{1}\begin{tabular}{@{} c @{}}
variable \\ dual
\end{tabular}} & \multicolumn{2}{c}{\displaystyle
\max \sum_{i = 1}^{m + 1} u_i a_i + \sum_{j = 1}^{n + 1} v_j b_j
} \\
\text{s.t.} &
\sum_{j = 1}^n x_{ij} - x_{i, n + 1} &= a \quad \forall i = 1, \dotsc, m &
u_i &
u_i + v_j &\leq c_{ij} \\
& \sum_{j = 1}^n x_{m + 1, j} + x_{m + 1, n + 1} &= a_{m + 1} &
u_{m + 1} &
-u_i - v_{n + 1} &\leq c_{i, n + 1} \\
& \sum_{i = 1}^m x_{ij} + x_{m + 1, j} &= b_j \quad \forall j = 1, \dotsc, n &
v_j &
u_{m + 1} + v_j &\leq c_{m + 1, j} \\
& -\sum_{i = 1}^m x_{i, n + 1} + x_{m + 1, n + 1} &= b_{n + 1} &
v_{n + 1} &
u_{m + 1} + v_{n + 1} &\leq c_{m + 1, n + 1} \\
& x_{ij} &\multicolumn{1}{@{} l @{}}{
\renewcommand{\arraystretch}{1.5}
{}\geq 0 \quad \left\{ \begin{array}{@{} l @{}}
\forall i = 1, \dotsc, m \\
\forall j = 1, \dotsc, n
\end{array}\right.
}
\end{array}
$}
\end{frame}
\end{document}
答案3
我对自己的问题找到了一个新的解决方案,其结果几乎令人满意。
\documentclass{beamer}
\usetheme{CambridgeUS}
\begin{document}
\begin{frame}{Primal-dual}
\begin{equation*}
\scriptsize
\begin{aligned}[c]
\text{Min} & \sum_{i=1}^{m+1}\sum_{j=1}^{n+1}c_{ij}x_{ij}\\
\text{s.a.} \quad
&\sum_{j=1}^{n}x_{ij}-x_{i,n+1}= a_i \qquad \forall i=1,\hdots,m\\
& \textcolor{blue}{\sum_{j=1}^{n}}x_{m+1,j}+\textcolor{magenta}{x_{m+1,n+1}}=a_{m+1}\\
&\sum_{i=1}^{m}x_{ij}+x_{m+1,j}= b_j \qquad \forall j=1,\hdots,n\\
-&\textcolor{red}{\sum_{i=1}^{m}}x_{i,n+1}+\textcolor{magenta}{x_{m+1,n+1}}=b_{n+1}\\
&x_{ij}\ge 0 \qquad
\left\{
\begin{aligned}
\forall i=&1,\hdots,m\\ \forall j=&1,\hdots,n\\
\end{aligned}
\right.
\end{aligned}
\quad
\begin{vmatrix}
\phantom{}\\
u_i \\
\phantom{}\\
\phantom{}\\
u_{m+1} \\
\phantom{}\\
\phantom{}\\
v_j \\
\phantom{}\\
\phantom{}\\
v_{n+1}\\
\phantom{}\\
\end{vmatrix}
\quad
\begin{aligned}[c]
\text{Max} & \sum_{i=1}^{m+1}u_i a_i+\sum_{j=1}^{n+1}v_j b_j\\
& \phantom{}\\
\text{s.a.} \quad
& u_i+v_j \le c_{ij}\\
& \\
-& u_i-v_{n+1} \le c_{i,n+1}\\
& \\
& u_{m+1}+v_j \le c_{m+1,j}\\
& \\
& u_{m+1}+v_{n+1} \le c_{{m+1},{n+1}}\\
& \phantom{}\\
& \phantom{}\\
& \phantom{}\\
& \phantom{}\\
\end{aligned}
\normalsize
\end{equation*}
\end{frame}
\end{document}