Is there any difference between set align(center)
and align(center, …)
?
#[
#set align(center)
…
]
// vs
#align(center)[…]
I know that the former changes the default alignment, while the latter calls the align
function.
But I also notice that many align
parameters use the outer alignment by default. For instance, table.align
:
…If set to
auto
, the outer alignment is used.
Default:auto
So will there be any visible difference?
My attempt
I failed to construct any counter example.
Full code
#let example = [
#lorem(15)
- a
- #context align.alignment
#align[
- a
- #context align.alignment
]
#align(start)[
- a
- #context align.alignment
]
#table(
columns: (2em,) * 2,
align: horizon,
[A], [B \ C],
)
#colbreak(weak: true)
]
#set page(width: 50em, height: auto, margin: 2em, columns: 3)
#set raw(lang: "typc")
#[
= Default
#example
]
#[
= `set align(center)`
#set align(center)
#example
]
#[
= `align(center, …)`
#align(center, example)
]
I also asked typst/typst | DeepWiki and found the following rust implementations.
It looks like the align
function does nothing but set align(…)
?
const ALIGN_RULE: ShowFn<AlignElem> =
|elem, _, styles| Ok(elem.body.clone().aligned(elem.alignment.get(styles)));
impl Content {
/// Set alignments for this content.
pub fn aligned(self, align: Alignment) -> Self {
self.styled(AlignElem::set_alignment(align))
}
}
Links to details
-
Translation: Why the inner
align
in#align(center, align{#lorem(3) \ #lorem(5)})
changes from the defaultstart
tocenter
, but the innerrect
in#rect(width: 20em, rect{#lorem(3) \ #lorem(5)})
does not change from the defaultauto
to20em
?
Additional notes
Our original question was set align(center)
vs. show: align.with(center)
.
I changed it to the current version to avoid being disturbed by show rule priority.