#let test(body, width: 2.3em) = box(width: width, stroke: (x: green), align(
center,
body,
))
#set page(width: auto, height: auto, margin: 1em)
#set text(
font: "Noto Serif CJK SC",
lang: "zh",
top-edge: "ascender",
bottom-edge: "descender",
)
#set raw(lang: "typc")
#show raw: set text(font: ("DejaVu Sans Mono", "Noto Serif CJK SC"))
#set table.hline(stroke: 0.5pt)
#table(
columns: 3,
stroke: none,
align: (horizon, center + horizon, horizon),
..(
([✅], `[国国TT]`),
table.hline(),
([❌], `[国国\ TT]`),
(
[❌],
`[国国] + linebreak() + [TT]
// Equivalent to the above`,
),
(
[❌],
`text(cjk-latin-spacing: auto)[国国\ TT]
// Equivalent to the above`,
),
([✅], `text(cjk-latin-spacing: none)[国国\ TT]`),
table.hline(),
([❌], `[国国\ T国]`),
([✅], `[国T\ T国]`),
([✅], `[国T\ 国国]`),
([✅], `[国国\ 国国]`),
)
.map(row => if type(row) == array and row.len() == 2 {
let (ok, body) = row
(ok, test(eval(body.text)), body)
} else { row })
.flatten(),
table.hline(),
[❌],
test(width: 2.3em)[国国\ TT],
[`[国国\ TT] + 2.3em`, where `2.3em` is width],
[❌], test(width: 2.5em)[国国\ TT], `[国国\ TT] + 2.5em`,
[❌], test(width: 2.8em)[国国\ TT], `[国国\ TT] + 2.8em`,
[❌], test(width: 3.5em)[国国\ TT], `[国国\ TT] + 3.5em`,
)
Original title: cjk-latin-space + manual linebreak + align(center) ⇒ Unexpected left shift
Description
If the line is broken manually between a CJK and a Latin character, then typst will insert an extra CJK-Latin space. This space becomes noticeable when text is aligned to the right or center.
In the following example, the text
国国is intended to be horizontally centered, but it appears slightly shifted to the left.This issue only occurs when
linebreak()or\.This issue is NOT related to the linebreaks algorithm, as it occurs in both
#set par(linebreaks: "simple")and#set par(linebreaks: "optimized").More examples
Full code
Additionally, the cjk-latin space also affects
align(end).Links
Reproduction URL
No response
Operating system
Windows, Web app
Typst version