Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有序列表、无序列表后跟中文,文本会向下偏移 #8

Open
1 task done
Cishoon opened this issue Jul 8, 2024 · 3 comments
Open
1 task done

有序列表、无序列表后跟中文,文本会向下偏移 #8

Cishoon opened this issue Jul 8, 2024 · 3 comments

Comments

@Cishoon
Copy link

Cishoon commented Jul 8, 2024

使用平台详情

  • 本地:Typst

工具:VSCode + Typst Preview插件

问题描述

有序列表和无序列表后跟中文,中文字符会向下偏移一些距离。

例如:

image

后面跟英文是正常的:

image

@Cishoon
Copy link
Author

Cishoon commented Jul 10, 2024

在用到有序列表的文件开头加上下面这段代码:

#show enum.item: it => [
  #set text(baseline: -2.5pt) if regex("[\u4e00-\u9fa5]") in it.body.text
  #it
]

#show list.item: it => [
  #set text(baseline: -2.5pt) if regex("[\u4e00-\u9fa5]") in it.body.text
  #it
]

可以识别出含有中文的一项,并把它向上平移一点。

但是尝试集成到tongjithesis.typ文件中时会报错

@Cishoon
Copy link
Author

Cishoon commented Jul 11, 2024

在用到有序列表的文件开头加上下面这段代码:

#show enum.item: it => [
  #set text(baseline: -2.5pt) if regex("[\u4e00-\u9fa5]") in it.body.text
  #it
]

#show list.item: it => [
  #set text(baseline: -2.5pt) if regex("[\u4e00-\u9fa5]") in it.body.text
  #it
]

可以识别出含有中文的一项,并把它向上平移一点。

但是尝试集成到tongjithesis.typ文件中时会报错

发现报错是因为我的文章中有些item.body中有空格,导致item.body的类型变成了一个content数组,没有了text属性。

tongjithesis.typ修改如下,就不会偏移了。但是写法实在不优雅。

  // show list: it => it + empty-par()
  // show enum: it => it + empty-par()

  show list: it => {
    for child in it.children [
      #it.marker.at(0)
      #h(0.5em)
      #child.body
      
    ]
  }
  show enum: it => {
    let index = 0
    for child in it.children {
      index = index + 1
      if child.has("number") [
        #child.number.
      ] else [
        #index.
      ]
      [
        #child.body
        
      ]
    }
  }

@RizhongLin
Copy link
Member

Hi,星云,

感谢你提出 Issue 并分享解决方案!

这个文本偏移问题可能与我们所用的中文字体有关。你有尝试过切换其他字体吗?有时不同字体的基线设置会影响对齐。如果更换字体后问题仍然存在,我们可以考虑在模板中做更通用的调整,避免每个列表项都手动调整;如果更换字体后问题被解决,我们可以考虑更换模版的默认字体。

谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants