Skip to content

Commit 4e02710

Browse files
committed
feat: add table and code block
1 parent 4e32cdf commit 4e02710

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
- [ ] 目录
4848
- [x] 一级序号和标题居中;二级序号和标题顶格;三级及以下标题“首行缩进” 2 字符
4949
- [x] 图片
50-
- [ ] 表格
50+
- [x] 表格
51+
- [x] 代码块
5152
- [ ] 页面脚注(开发人员说后续会加上的 [#222](https://github.com/typst/typst/discussions/222)
5253
- [x] 页码字体改为小五号 Times New Man
5354
- [x] 数学公式

main.typ

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,57 @@
2424
// 正文
2525
= 基础模块
2626

27+
我认为 Typst 介于 LaTeX 和 Markdown 之间。在你开始使用这个模板之前,你可以对 LaTeX 不那么熟悉,但确保你对 Markdown 有一定了解,并且我建议学习一下如何使用 Typst 。
28+
2729
== 图示例
2830

29-
#Figure("images/bupt.png", "label", 30%)
31+
#Figure("images/bupt.png", "北京邮电大学校徽", 30%)
32+
33+
这是一幅图。
34+
35+
== 表格示例
36+
37+
#Table(
38+
"北京邮电大学历年录取分数线",
39+
(auto, auto, auto, auto, auto),
40+
horizon,
41+
(
42+
[*年份*], [*录取批次*], [*招生类型*], [*最低分/最低位次*], [*省控线*],
43+
[2018], [本科一批], [普通类], [649/2469], [532],
44+
[2017], [本科一批], [普通类], [635/2548], [537],
45+
[2016], [本科一批], [宏福校区], [621/--], [548],
46+
[2015], [本科一批], [普通类], [646/2499], [548],
47+
[2014], [本科一批], [普通类], [--/--], [548],
48+
)
49+
)
3050

31-
这是一个北邮校徽
51+
这是一张表。注意到了吗?这里并没有自动段首空格,因为我们还在上一段里。要想在后面开启新的一段,需要自己手动输入换行符“\\”。后面没有空格的原理是一样的
3252

3353
== 公式示例
3454

3555
下方是一个简单的求圆的面积的公式:
3656

3757
$ S = pi r^2 $
3858

39-
语法跟 Markdown 很像,比较容易上手。注意到了吗?这里并没有自动段首空格。要想在公式后开启新的一段,需要自己手动输入换行符“\\”。
59+
语法跟 Markdown 很像,比较容易上手。
4060

4161
== 引用示例
4262

4363
这是一个参考文献的引用@webster_social_media 。但是具体的格式还不正确。
4464

65+
== 代码示例
66+
67+
这是一段用示例代码。
68+
69+
```cpp
70+
void setFib(void)
71+
{
72+
fib(1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 | 89, 10);
73+
}
74+
```
75+
76+
Typst 还支持书写行内的代码,就像 Markdown 一样,比如 `return n * f(n - 1)`
77+
4578
// 附页
4679
#show: Appendix.with(
4780
bibliographyFile: "reference.bib"
@@ -55,9 +88,11 @@ $ S = pi r^2 $
5588
#pagebreak()
5689
= 附#h(2em)录
5790

58-
== 附录1
91+
== 附录 1
92+
93+
这是一个附录内容,学校规定附录的二级标题得是附录二字后接阿拉伯数字。
5994

60-
这是一个附录内容,学校规定附录的二级标题得是附录1、附录2这样子
95+
但是 Typst 的中文与英文和数字之间的空格并没有像 LaTeX 那样自动空出,所以就需要自己手打了
6196

6297
#pagebreak()
6398
= 外#h(1em)文#h(1em)译#h(1em)文

template.typ

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// 三号 16pt,小三号 15pt,四号 14pt,小四号 12pt,五号 10.5pt,小五号 9pt
22

33
#let FONTSET = (
4-
Hei: "Noto Sans CJK SC",
5-
Song: "Noto Serif CJK SC",
6-
Kai: "FZKai-Z03",
4+
Hei: "Noto Sans CJK SC",
5+
Song: "Noto Serif CJK SC",
6+
Kai: "FZKai-Z03",
77
English: "Times New Roman",
88
)
99
// #set text(font: "STIX Two Text")
1010

11-
#let figureCounter = counter("Figure")
11+
#let tableCounter = counter("Table")
12+
#let figureCounter = counter("Figure")
1213
#let equationCounter = counter("Equation")
1314

1415
#let BUPTBachelorThesis(
@@ -45,6 +46,12 @@
4546
equationCounter.step()
4647
})
4748

49+
// 代码
50+
show raw.where(block: true): it => {
51+
set block(stroke: 0.5pt, width: 100%, inset: 1em)
52+
it
53+
}
54+
4855
// 中文摘要
4956
align(center)[
5057
#set text(font: FONTSET.at("Hei"), weight: "bold")
@@ -109,6 +116,7 @@
109116

110117
if it.level == 1 {
111118
// 重置计数器
119+
tableCounter.update(1)
112120
figureCounter.update(1)
113121
equationCounter.update(1)
114122

@@ -179,4 +187,29 @@
179187
figure(
180188
image(file, width: width)
181189
)
190+
}
191+
192+
#let Table(caption, columnsSet, alignSet, body) = {
193+
show table: it => locate(loc => {
194+
let chapterLevel = counter(heading).at(loc).at(0)
195+
196+
align(center)[
197+
#text(
198+
font: (FONTSET.at("English"), FONTSET.at("Kai")),
199+
size: 10.5pt,
200+
[表 #chapterLevel\-#tableCounter.display() #caption]
201+
)
202+
#it
203+
]
204+
205+
tableCounter.step()
206+
})
207+
208+
table(
209+
columns: columnsSet,
210+
align: alignSet,
211+
inset: 8pt,
212+
stroke: 0.5pt,
213+
..body
214+
)
182215
}

0 commit comments

Comments
 (0)