![跨案例对齐](https://linux22.com/image/395015/%E8%B7%A8%E6%A1%88%E4%BE%8B%E5%AF%B9%E9%BD%90.png)
我有以下方程式:
我想对齐所有等号以及 for-all 语句,并在每个括号的左侧垂直居中放置一个解释性词。
我目前的代码如下。这只是一系列案例。我不确定如何强制案例之间的对齐或处理每个案例中的多个等号。
垂直对齐说明性文字也有问题,但我想我可以用不间断空格或水平盒子来解决这个问题。
\documentclass{article}
\usepackage{amsmath}
\usepackage{rotating}
\begin{document}
\begin{align}
\begin{rotate}{90}
Init
\end{rotate}
&\begin{cases}
P_{1,1} &= P_0 \\
S_{1,1} &= S_0 \\
R_{1,1} &= R_0 \\
\end{cases} \\
&\begin{cases}
g(P_{y,t}) &= u_{y,t,P}+u_{y,t,S}+u_{y,t,R} \forall y \forall t>1 \\
\end{cases} \\
&\begin{cases}
P_{y,t+1} &= P_{y,t}+c_P \cdot u_{y,t,P}\cdot\Delta t \forall y \forall t<T \\
S_{y,t+1} &= S_{y,t}+c_S \cdot u_{y,t,S}\cdot\Delta t \forall y \forall t<T \\
R_{y,t+1} &= R_{y,t}+c_R \cdot u_{y,t,R}\cdot\Delta t \forall y \forall t<T \\
\end{cases} \\
&\begin{cases}
P_{y,1} &= \gamma_P P_{y-1,T}+\gamma_W S_{y-1,T} \forall y>1 \\
S_{y,1} &= 0 \forall y>1 \\
R_{y,1} &= 0 \forall y>1
\end{cases}
\end{align}
\end{document}
答案1
我只会使用rotating
其他sidewaystable
功能,例如rotate
环境,实际上只是为了与旧版 latex2.09 软件包兼容,该软件包graphicx
是基于旧版 latex2.09 的。它只是一个非常薄的兼容性包装器,graphicx
在这种情况下,失去了将旋转设置为围绕中心的选项。
对于其余部分,我只是强制了一些明确的间距,唯一棘手的一点是,大号的{
比标准号的更宽。
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\begin{align}
\rotatebox[origin=c]{90}{Init}
&\begin{cases}
\makebox[2.5em][l]{$P_{1,1} $}&= P_0 \\
\makebox[2.5em][l]{$S_{1,1} $}&= S_0 \\
\makebox[2.5em][l]{$R_{1,1} $}&= R_0 \\
\end{cases} \\
&\begin{cases}
\sbox0{$\Bigg\{$}
\sbox2{$\big\{$}
\kern\dimexpr\wd0-\wd2\relax
\makebox[2.5em][l]{$g(P_{y,t}) $}&= u_{y,t,P}+u_{y,t,S}+u_{y,t,R} \forall y \forall t>1 \\
\end{cases} \\
&\begin{cases}
\makebox[2.5em][l]{$P_{y,t+1} $}&= P_{y,t}+c_P \cdot u_{y,t,P}\cdot\Delta t \forall y \forall t<T \\
\makebox[2.5em][l]{$S_{y,t+1} $}&= S_{y,t}+c_S \cdot u_{y,t,S}\cdot\Delta t \forall y \forall t<T \\
\makebox[2.5em][l]{$R_{y,t+1} $}&= R_{y,t}+c_R \cdot u_{y,t,R}\cdot\Delta t \forall y \forall t<T \\
\end{cases} \\
&\begin{cases}
\makebox[2.5em][l]{$P_{y,1} $}&= \gamma_P P_{y-1,T}+\gamma_W S_{y-1,T} \forall y>1 \\
\makebox[2.5em][l]{$S_{y,1} $}&= 0 \forall y>1 \\
\makebox[2.5em][l]{$R_{y,1} $}&= 0 \forall y>1
\end{cases}
\end{align}
\end{document}
答案2
这是使用该包的建议eqparbox
。它需要一些编译。
第二个案例所需的调整归功于戴维斯·卡莱尔。
\documentclass{article}
\usepackage{amsmath}
\usepackage{rotating}
\usepackage{eqparbox}
\newcommand\MB[3][]{%
\eqmakebox[#2][#1]{$#3$}
}
\begin{document}
\begin{align}
\begin{rotate}{90}
Init
\end{rotate}
&
\begin{cases}
\MB[r]{A}{P_{1,1}} = \MB[l]{B}{P_0} \\
\MB[r]{A}{S_{1,1}} = \MB[l]{B}{S_0} \\
\MB[r]{A}{R_{1,1}} = \MB[l]{B}{R_0} \\
\end{cases} \\
&
\begin{cases}
% manually adjusted bacause of the { width difference
\sbox0{$\Bigg\{$}
\sbox2{$\big\{$}
\kern\dimexpr\wd0-\wd2\relax
\MB[r]{A}{g(P_{y,t})} = \MB[l]{B}{u_{y,t,P}+u_{y,t,S}+u_{y,t,R}} & \forall y \forall t>1 \\
\end{cases} \\
&
\begin{cases}
\MB[r]{A}{P_{y,t+1}} = \MB[l]{B}{P_{y,t}+c_P \cdot u_{y,t,P}\cdot\Delta t} & \forall y \forall t<T \\
\MB[r]{A}{S_{y,t+1}} = \MB[l]{B}{S_{y,t}+c_S \cdot u_{y,t,S}\cdot\Delta t} & \forall y \forall t<T \\
\MB[r]{A}{R_{y,t+1}} = \MB[l]{B}{R_{y,t}+c_R \cdot u_{y,t,R}\cdot\Delta t} & \forall y \forall t<T \\
\end{cases} \\
&
\begin{cases}
\MB[r]{A}{P_{y,1}} = \MB[l]{B}{\gamma_P P_{y-1,T}+\gamma_W S_{y-1,T}} & \forall y>1 \\
\MB[r]{A}{S_{y,1}} = \MB[l]{B}{0} & \forall y>1 \\
\MB[r]{A}{R_{y,1}} = \MB[l]{B}{0} & \forall y>1
\end{cases}
\end{align}
\end{document}
答案3
这是另一个选项,使用matrix of nodes
来自蒂克兹包裹。
这里有一点技巧tikpage节点“手动”放置方程编号。等号的对齐并不完美,但可以matrix of nodes
让您完全控制要添加到这些方程中的任何“装饰”。
代码如下:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{matrix,fit,decorations.pathreplacing}
\begin{document}
\begin{center}
\begin{tikzpicture}[remember picture]
\matrix (M)[
matrix of math nodes,
column 1/.style = {anchor=base east, minimum width=3.6em},
column 2/.style = {anchor=base west},
column 3/.style = {anchor=base west},
]{
P_{1,1} &= P_0 \\
S_{1,1} &= S_0 \\
R_{1,1} &= R_0 \\
g(P_{y,t}) &= u_{y,t,P}+u_{y,t,S}+u_{y,t,R} &\forall y \forall t>1 \\
P_{y,t+1} &= P_{y,t}+c_P \cdot u_{y,t,P}\cdot\Delta t &\forall y \forall t<T \\
S_{y,t+1} &= S_{y,t}+c_S \cdot u_{y,t,S}\cdot\Delta t &\forall y \forall t<T \\
R_{y,t+1} &= R_{y,t}+c_R \cdot u_{y,t,R}\cdot\Delta t &\forall y \forall t<T \\
P_{y,1} &= \gamma_P P_{y-1,T}+\gamma_W S_{y-1,T} &\forall y>1 \\
S_{y,1} &= 0 &\forall y>1 \\
R_{y,1} &= 0 &\forall y>1 \\
};
% add braces around equation groups
\foreach \top/\bot/\lab in {1/3, 4/4, 5/7, 8/10} {
\draw[thick,decorate, decoration={mirror,brace}]
([yshift=-1pt]M-\top-1.north west)--([yshift=1pt]M-\bot-1.south west);
}
% add the init label
\node[rotate=90] at ([xshift=-3mm]M-2-1.west){Init};
% and now add the equation lines, using tikzpagenodes to put
% them on the righthand margin
\begin{scope}[overlay]
\foreach \eq in {2,4,6,9} {
\refstepcounter{equation}
\node[anchor=east] at ([xshift=-3em]M-\eq-1-|current page text area.east) {(\theequation)};
}
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}
答案4
我最终融合了几个答案并添加了额外的空间,因为我不喜欢其中一个括号比其他括号窄:
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{eqparbox}
\newcommand\MB[3][]{%
\eqmakebox[#2][#1]{$#3$}
}
\begin{document}
{\small\allowdisplaybreaks
\begin{align}
\rotatebox[origin=c]{90}{\footnotesize \parbox{1.8cm}{\centering Initial \\ Conditions}}
&\left\{
\begin{aligned} \label{equ:mod1_init}
\MB[r]{A}{P_{1,1}} = \MB[l]{B}{P_0} \\
\MB[r]{A}{S_{1,1}} = \MB[l]{B}{S_0} \\
\MB[r]{A}{R_{1,1}} = \MB[l]{B}{R_0} \\
\end{aligned}
\right. \\
\rotatebox[origin=c]{90}{\footnotesize \parbox{1.8cm}{\centering Mass\\ Conservation}}
&\left\{
\begin{aligned} \label{equ:mod1_masscons}
% manually adjusted bacause of the { width difference
\sbox0{$\Bigg\{$}
\sbox2{$\big\{$}
\kern\dimexpr\wd0-\wd2\relax
&&\\
\MB[r]{A}{g(P_{y,t})} &= \MB[l]{B}{u_{y,t,P}+u_{y,t,S}+u_{y,t,R}} & \forall y \forall t>1 \\
&&\\
\end{aligned}
\right. \\
\rotatebox[origin=c]{90}{\footnotesize Integration}
&\left\{
\begin{aligned} \label{equ:mod1_integration}
\MB[r]{A}{P_{y,t+1}} &= \MB[l]{B}{P_{y,t}+c_P \cdot u_{y,t,P}\cdot\Delta t} & \forall y \forall t<T \\
\MB[r]{A}{S_{y,t+1}} &= \MB[l]{B}{S_{y,t}+c_S \cdot u_{y,t,S}\cdot\Delta t} & \forall y \forall t<T \\
\MB[r]{A}{R_{y,t+1}} &= \MB[l]{B}{R_{y,t}+c_R \cdot u_{y,t,R}\cdot\Delta t} & \forall y \forall t<T \\
\end{aligned}
\right. \\
\rotatebox[origin=c]{90}{\footnotesize Continuity}
&\left\{
\begin{aligned} \label{equ:mod1_continuity}
\MB[r]{A}{P_{y,1}} &= \MB[l]{B}{\gamma_P P_{y-1,T}+\gamma_W S_{y-1,T}} & \forall y>1 \\
\MB[r]{A}{S_{y,1}} &= \MB[l]{B}{0} & \forall y>1 \\
\MB[r]{A}{R_{y,1}} &= \MB[l]{B}{0} & \forall y>1
\end{aligned}
\right.
\end{align}
}
\end{document}