Skip to content

如何让 cases 中某列右对齐?

如何让 cases 中某列右对齐?

cases中的内容刻意全部左对齐

typst
$ f = cases(
  137 & "if" (n+1) in NN,
  0   & "otherwise",
) $
Typst compiled image

若想让“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"
$) $
Typst compiled image

不过这样括号大小与两行间距可能与原版cases略有差异。如果介意,可调整lrsize参数boxinset参数,例如设置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"
$) $
Typst compiled image

并非最新版

上例使用 v0.14.2 编译,可能不适用于最新版。

另请参见

贡献者

页面历史

Comments
  • Latest
  • Oldest
  • Hottest

基于 MIT 许可发布