Skip to content

Too wide spacing between heading numbering and title in CJK #5778

Open

Description

@hongjr03

Description

I noticed that typst will automatically add a 0.3em width space after the heading's numbering, which is usually fine, but Chinese is used to use the full-width symbols 、 as the symbol for the heading's numbering, and both the full-width symbols 、 and the 0.3em width space create a part of the space that can lead to too wide a space between the heading's numbering and its content.

Image

although h(0.3em) can be shown as none by the show rule, i think it is possible to add kerning to the numbering, considering that users who have not read the source code may not know the amount of 0.3em.

Reproduction URL

https://typst.app/project/rtKJvE6vqm8aq5bDuQi9Jh

Operating system

macOS

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Jan 29, 2025
  2. changed the title [-]Incorrect spacing in heading between full-width numbering symbols and content[/-] [+]Too wide spacing between heading numbering and title in CJK[/+] on Feb 6, 2025
  3. added
    text
    cjk
    on Feb 6, 2025
  4. YDX-2147483647 commented on Aug 4, 2025

    @YDX-2147483647
    Contributor

    There is also a need to increase the width (or more precisely, fix the width of numbering+spacing) here. #2351

    Each heading may have at least four forms

    These form may not all be the same.
    Just providing four parameters can solve the problem, but it's too complicated…

    Image

    Comparisons

    displaying ≠ referenced ∧ outlined ≠ referenced ∧ bookmarked ≠ referenced (一、标题 ≠ 第一章)

    Of course they might be different!

    The issue is that there are numerous possibilities for permutations/subsets of

    • numbering (which may have different forms, e.g., 1.1. vs. 1.1, or 一、 vs. 一),
    • separator (#h(0.3em), #h(1em), or 2em - measure(numbering).width),
    • supplement (which may consist of two parts, as in 第{1:一}章),
    • and the page number.

    Currently, there is no simple way to customize those forms separately, unless you reconstruct ref completely and ignore all tricky things about context, styling, query, etc.

    displaying ≠ outlined (1. The case of $2/3$ and \ blah blah blah blah ≠ 1. The case of $2\/3$ and blah)

    The outlined heading might be shorter. In addition, the number and position of manual #linebreak in them might differ.

    In Chinese, for special short headings (such as 译后记 Postscript in the image below), the characters might be arranged loosely, but only when displaying.

    Image

    It can be achieved in typst 0.13.1, though kind of odd:

    #[
      #set text(tracking: 3em / 4)
      = 译后记
    ]
    
    // Instead of:
    // = #text(tracking: 3em / 4)[译后记]
    displaying ≠ bookmarked ∧ outlined ≠ bookmarked (1. Considering $2/3$ ≠ 1. Considering 2/3)

    Only plain text is allowed in the bookmarked form.
    As a result, math equations, rubies, and special spacings should take a different form.

    In typst 0.13.1, #h(0.3em) and#h(1em) become void when bookmarked, while $2/3$ becomes 23.

    The separator between the numbering and content was discussed in #6622:

    I'm open to trying to find a way to make it work nicely in more languages, but it should also work for English.

    That makes sense. In fact, not all numbering formats in Chinese (and Japanese, I guess) do not require spaces. "1." definitely needs a space, while 第一章 requires a full-width space.

  5. Serenade600 commented on Aug 14, 2025

    @Serenade600

    Microsoft's Word, born in 1980s and being the most commonly used editor across China, cannot handle the issue stated in title.

  6. Ikaluk commented on Nov 22, 2026

    @Ikaluk

    Compare this issue, where the default spacing needs to be removed too.
    flaribbit/numbly#5

  7. YDX-2147483647 commented on Nov 25, 2026

    @YDX-2147483647
    Contributor

    With the merge of typst/codex#182 and #7350, is it possible to auto-magically remove the spacing betweeen 一、 and 汉字?
    After all, the following code now works as expected to some degree.

    #let heading(numbering: "", body) = [
      #numbering
      #body
    ]
    
    - #heading(numbering: "1.")[Latin]
    - #heading(numbering: "一、")[汉字]
    // Output:
    1. Latin // A space is added
    一、汉字 // No space is added

    Problems:

    1. The space in 1. 汉字 is still wanted.
    2. Do Korean articles use 一、? Should the space be kept?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcjktext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions