如何让 cases 中某列右对齐?
cases中的内容刻意全部左对齐。
typst
$ f = cases(
137 & "if" (n+1) in NN,
0 & "otherwise",
) $
若想让“otherwise”这列右对齐,可以换用lr,使用&交替左右对齐:
typst
#let lrcases(it) = math.lr(${$ + box(
baseline: (at: horizon, shift: -0.25em),
it,
))
#lrcases($
& 137 & "if" (n+1) in NN \
& 0 & "otherwise"
$)
$ f = #lrcases($
& 137 & "if" (n+1) in NN \
& 0 & "otherwise"
$) $
不过这样括号大小与两行间距可能与原版cases略有差异。如果介意,可调整lr的size参数或box的inset参数,例如设置math.lr(size: 110%, …)或box(inset: (y: 0.1em), …)。
适用于 Typst v0.14.2 的旧方法
typst
#let lrcases(it) = math.lr($\{$ + block(it))
#lrcases($
& 137 & "if" (n+1) in NN \
& 0 & "otherwise"
$)
$ f = #lrcases($
& 137 & "if" (n+1) in NN \
& 0 & "otherwise"
$) $
并非最新版
上例使用 v0.14.2 编译,可能不适用于最新版。
另请参见
- Right-Align Equations in `cases` · typst#1191 (open issue)
- right/left alignment of equations doesn't work in `cases` function · typst#1478 (closed issue, not planned)
- Revision of the cases function · typst#1767 (open issue)
- wrong alignment of cases · typst#2562 (closed issue, not planned)
- In Typst 0.15 unexpected default `baseline` of `box` in multiline equation within `lr` · typst#8516 (open issue)
Y.D.X.