Skip to content

Commit 2dccfa5

Browse files
committed
fix: repetitive heading spacing
Signed-off-by: Juntong Chen <[email protected]>
1 parent 578f0ac commit 2dccfa5

File tree

6 files changed

+38
-56
lines changed

6 files changed

+38
-56
lines changed

Diff for: layouts/mainmatter.typ

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import "@preview/i-figured:0.2.4"
22
#import "../utils/style.typ": 字号, 字体
33
#import "../utils/custom-numbering.typ": custom-numbering
4-
#import "../utils/custom-heading.typ": heading-display, active-heading, current-heading, heading-content
4+
#import "../utils/custom-heading.typ": heading-content
55
#import "../utils/indent.typ": fake-par
66
#import "../utils/unpairs.typ": unpairs
77
#import "../utils/pagebreak-from-odd.typ": pagebreak-from-odd
@@ -25,10 +25,10 @@
2525
text-args: auto,
2626
// 标题字体与字号
2727
heading-font: auto,
28-
heading-size: (字号.三号, 字号.四号,),
28+
heading-size: (字号.三号, 字号.四号, 字号.四号, 字号.小四),
2929
heading-weight: ("regular",),
30-
heading-above: (1.0em, 2.0em, 1.5em),
31-
heading-below: (1.5em, 1.5em, 1.25em),
30+
heading-above: (1.5em, 2.5em),
31+
heading-below: (2.0em, 1.5em),
3232
heading-pagebreak: (true, false),
3333
heading-align: (center, auto),
3434
// 页眉
@@ -101,7 +101,7 @@
101101
first-line-indent: first-line-indent
102102
)
103103
// show par: set block(spacing: spacing)
104-
show raw: set text(font: fonts.等宽)
104+
show raw: set text(font: fonts.等宽, size: text-args.size)
105105
show raw.where(block: true): set par(leading: 1em)
106106
// 3.2 脚注样式
107107
show footnote.entry: set text(font: fonts.宋体, size: 字号.五号)
@@ -110,6 +110,7 @@
110110
show figure: show-figure
111111
// 3.4 设置 equation 的编号和假段落首行缩进
112112
show math.equation.where(block: true): show-equation
113+
show math.equation.where(block: true): set block(inset: (y: 0.3em, x: 0em))
113114
// 3.5 表格表头置顶 + 不用冒号用空格分割 + 样式
114115
show figure.where(
115116
kind: table
@@ -166,7 +167,7 @@
166167
above: array-at(heading-above, it.level),
167168
below: array-at(heading-below, it.level),
168169
)
169-
it
170+
it + fake-par + v(-0.15em)
170171
}
171172
// 4.3 标题居中与自动换页
172173
show heading: it => context {
@@ -183,6 +184,26 @@
183184
it
184185
}
185186
}
187+
// 4.4 防止标题间距重复 https://github.com/typst/typst/issues/2953#issuecomment-1858823455
188+
show heading : it => context {
189+
// Finds all previous headings, inclusive
190+
let elems = query(selector(heading).before(here()))
191+
if elems.len() > 1 { // If there are at least 2
192+
let prev-heading = elems.at(-2)
193+
if (
194+
prev-heading.level > 1 and
195+
prev-heading.location().page() == it.location().page() and
196+
prev-heading.location().position().y + 60pt > it.location().position().y
197+
) [
198+
#v(-calc.abs(array-at(heading-above, it.level) - array-at(heading-below, it.level)))
199+
#it
200+
] else [
201+
#it
202+
]
203+
} else [
204+
#it
205+
]
206+
}
186207

187208
// 重置 footnote 计数器
188209
if reset-footnote {
@@ -218,7 +239,7 @@
218239

219240
// 列表样式
220241
set enum(indent: 0.9em, body-indent: 0.35em)
221-
set list(indent: 1em, body-indent: 0.55em)
242+
set list(indent: 2em, body-indent: 0.55em)
222243

223244
// 引述文本样式
224245
set quote(block: true)
@@ -227,10 +248,9 @@
227248

228249
set underline(stroke: 0.5pt + black, offset: 0.35em)
229250

230-
// 处理一些元素后第一段文本的首行缩进
231-
show selector.or(heading, figure, list, enum, quote, terms): it => {
232-
it
233-
fake-par
251+
// 处理其他元素后第一段文本的首行缩进
252+
show selector.or(figure, list, enum, quote, terms): it => {
253+
it + fake-par
234254
}
235255

236256
// 处理一级标题的引用格式

Diff for: lib.typ

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @project: modern-ecnu-thesis
55
* @author: OrangeX4, Juntong Chen ([email protected])
66
* @created: 2025-01-06 22:37:34
7-
* @modified: 2025-01-12 14:38:55
7+
* @modified: 2025-01-23 04:45:57
88
*
99
* 华东师范大学学位论文模板
1010
* Repo: https://github.com/jtchen2k/modern-ecnu-thesis
@@ -35,7 +35,6 @@
3535
#import "utils/custom-cuti.typ": *
3636
#import "utils/bilingual-bibliography.typ": bilingual-bibliography
3737
#import "utils/custom-numbering.typ": custom-numbering
38-
#import "utils/custom-heading.typ": heading-display, active-heading, current-heading
3938
#import "utils/indent.typ": indent, fake-par, no-indent
4039
#import "utils/panic-page.typ": panic-page
4140
#import "utils/word-counter.typ": *

Diff for: pages/bachelor-outline-page.typ

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "@preview/outrageous:0.1.0"
1+
#import "@preview/outrageous:0.3.0"
22
#import "../utils/invisible-heading.typ": invisible-heading
33
#import "../utils/style.typ": 字号, 字体
44
#import "../utils/custom-heading.typ": heading-content

Diff for: pages/list-of-figures.typ

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "@preview/i-figured:0.2.4"
2-
#import "@preview/outrageous:0.1.0"
2+
#import "@preview/outrageous:0.3.0"
33
#import "../utils/invisible-heading.typ": invisible-heading
44
#import "../utils/style.typ": 字号, 字体
55
#import "../utils/custom-heading.typ": heading-content

Diff for: pages/list-of-tables.typ

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "@preview/i-figured:0.1.0"
2-
#import "@preview/outrageous:0.1.0"
2+
#import "@preview/outrageous:0.3.0"
33
#import "../utils/invisible-heading.typ": invisible-heading
44
#import "../utils/style.typ": 字号, 字体
55
#import "../utils/custom-heading.typ": heading-content

Diff for: utils/custom-heading.typ

+3-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#import "style.typ": 字号
2+
#import "@preview/hydra:0.5.2": hydra
3+
24
// 展示一个标题
35
#let heading-display(it) = {
46
if it != none {
@@ -12,44 +14,6 @@
1214
}
1315
}
1416

15-
// 获取当前激活的 heading,参数 prev 用于标志优先使用之前页面的 heading
16-
#let active-heading(level: 1, prev: true) = {
17-
// 之前页面的标题
18-
let prev-headings = query(selector(heading.where(level: level)).before(here()))
19-
// 当前页面的标题
20-
let cur-headings = query(selector(heading.where(level: level)).after(here()))
21-
.filter(it => it.location().page() == here().page())
22-
if prev-headings.len() == 0 and cur-headings.len() == 0 {
23-
return none
24-
} else {
25-
if prev {
26-
if prev-headings.len() != 0 {
27-
return prev-headings.last()
28-
} else {
29-
return cur-headings.first()
30-
}
31-
} else {
32-
if cur-headings.len() != 0 {
33-
return cur-headings.first()
34-
} else {
35-
return prev-headings.last()
36-
}
37-
}
38-
}
39-
}
40-
41-
// 获取当前页面的标题
42-
#let current-heading(level: 1) = {
43-
// 当前页面的标题
44-
let cur-headings = query(selector(heading.where(level: level)).after(here()))
45-
.filter(it => it.location().page() == here().page())
46-
if cur-headings.len() != 0 {
47-
return cur-headings.first()
48-
} else {
49-
return none
50-
}
51-
}
52-
5317
// 页眉内容
5418
#let heading-content(
5519
twoside: false,
@@ -69,8 +33,7 @@
6933
context {
7034
let page = counter(page).get().at(0)
7135
// 获取当前页面的一级标题
72-
let cur-heading = current-heading(level: 1)
73-
let first-level-heading = if cur-heading != none { heading-display(cur-heading) } else { heading-display(active-heading(level: 1)) }
36+
let first-level-heading = hydra(1, skip-starting: false)
7437
let docinfo = "华东师范大学" + if doctype == "master" { "硕士" } else { "博士" } + "学位论文"
7538
set text(font: fonts.宋体, size: 字号.五号)
7639
if twoside {

0 commit comments

Comments
 (0)