|
| 1 | +// =========================== |
| 2 | +// HFUT 课程设计报告模板库 |
| 3 | +// =========================== |
| 4 | + |
| 5 | +// =========================== |
| 6 | +// 第三方库导入 |
| 7 | +// =========================== |
| 8 | +// 导入i-figured库用于公式和图表编号管理 |
| 9 | +#import "@preview/i-figured:0.2.4" |
| 10 | +// 导入格式化工具库(包含中文加粗、斜体、下划线等功能) |
| 11 | +#import "@preview/zh-format:0.1.0": * |
| 12 | + |
| 13 | +// =========================== |
| 14 | +// 主函数:报告模板配置 |
| 15 | +// =========================== |
| 16 | +#let hfut_report( |
| 17 | + // 基本信息(默认为空) |
| 18 | + title: "", |
| 19 | + department: "", |
| 20 | + major: "", |
| 21 | + class: "", |
| 22 | + author: "", |
| 23 | + student_id: "", |
| 24 | + supervisor: "", |
| 25 | + date: "", |
| 26 | + // 摘要和关键词 |
| 27 | + abstract: [摘要内容...], |
| 28 | + keywords: ("关键词1", "关键词2"), |
| 29 | + // 摘要页开关(true:显示摘要页,false:不显示摘要页) |
| 30 | + show_abstract: true, |
| 31 | + // 页眉配置参数 |
| 32 | + header_logo_height: 0.8cm, |
| 33 | + header_title_size: 9pt, |
| 34 | + header_line_stroke: 0.4pt, |
| 35 | + // 段落首行缩进配置 |
| 36 | + first-line-indent: 0em, |
| 37 | + // equation 计数 |
| 38 | + show-equation: i-figured.show-equation, |
| 39 | + body, |
| 40 | +) = { |
| 41 | + // =========================== |
| 42 | + // 全局样式配置 |
| 43 | + // =========================== |
| 44 | + |
| 45 | + // 应用中文格式化(粗体、下划线、斜体) |
| 46 | + show: zh-format |
| 47 | + |
| 48 | + // 文档元数据 |
| 49 | + set document(author: author, title: title) |
| 50 | + |
| 51 | + // 页面设置 |
| 52 | + set page( |
| 53 | + paper: "a4", |
| 54 | + margin: (top: 2.5cm, bottom: 2.5cm, left: 2.2cm, right: 2.2cm), |
| 55 | + ) |
| 56 | + |
| 57 | + // 正文字体设置:Times New Roman + 宋体 |
| 58 | + set text( |
| 59 | + font: ("Times New Roman", "SimSun"), |
| 60 | + lang: "zh", |
| 61 | + size: 12pt, |
| 62 | + ) |
| 63 | + |
| 64 | + // 段落格式设置:两端对齐 |
| 65 | + set par( |
| 66 | + justify: true, |
| 67 | + leading: 0.65em, |
| 68 | + first-line-indent: 0em, // 默认不缩进 |
| 69 | + ) |
| 70 | + |
| 71 | + // 标题间距设置 |
| 72 | + show heading: set block(above: 1.4em, below: 1em) |
| 73 | + |
| 74 | + // 代码块样式设置 |
| 75 | + show raw.where(block: true): block.with( |
| 76 | + fill: luma(240), |
| 77 | + inset: 10pt, |
| 78 | + radius: 4pt, |
| 79 | + width: 100%, |
| 80 | + stroke: 0.5pt + luma(200), |
| 81 | + ) |
| 82 | + |
| 83 | + // 行内代码样式 |
| 84 | + show raw.where(block: false): box.with( |
| 85 | + fill: luma(240), |
| 86 | + inset: (x: 3pt, y: 0pt), |
| 87 | + outset: (y: 3pt), |
| 88 | + radius: 2pt, |
| 89 | + ) |
| 90 | + |
| 91 | + // 脚注格式设置:[1] [2] 格式的蓝色上标 |
| 92 | + show footnote: set text(blue) |
| 93 | + set footnote(numbering: "[1]") |
| 94 | + |
| 95 | + // 每个标题时重置计数器 |
| 96 | + show heading: i-figured.reset-counters |
| 97 | + |
| 98 | + // 设置 equation 的编号(只对块级公式编号,<-> 标签取消编号) |
| 99 | + show math.equation.where(block: true): show-equation.with( |
| 100 | + only-labeled: false, |
| 101 | + unnumbered-label: "-", |
| 102 | + ) |
| 103 | + |
| 104 | + // 图表标题样式 |
| 105 | + show figure.caption: set text(font: ("Times New Roman", "SimHei"), size: 10pt) |
| 106 | + |
| 107 | + // 表格样式 |
| 108 | + show table: set text(size: 10pt) |
| 109 | + |
| 110 | + // =========================== |
| 111 | + // 封面页 |
| 112 | + // =========================== |
| 113 | + { |
| 114 | + set align(center) |
| 115 | + set page(header: none, footer: none, numbering: none) |
| 116 | + |
| 117 | + v(0.5cm) |
| 118 | + image("template/assets/HFUT_badge_zh&en_Vertical.svg", width: 7cm) |
| 119 | + v(1cm) |
| 120 | + |
| 121 | + text(22pt, font: ("Times New Roman", "SimSun"))[ |
| 122 | + *#underline[#title] 课程设计报告* |
| 123 | + ] |
| 124 | + |
| 125 | + v(3cm) |
| 126 | + |
| 127 | + grid( |
| 128 | + columns: (auto, 14em), |
| 129 | + rows: auto, |
| 130 | + gutter: 1em, |
| 131 | + row-gutter: 1.2em, |
| 132 | + align: (right, center), |
| 133 | + |
| 134 | + text(18pt, font: ("Times New Roman", "SimSun"))[*学 院:*], |
| 135 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#department]], |
| 136 | + |
| 137 | + text(18pt, font: ("Times New Roman", "SimSun"))[*专 业:*], |
| 138 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#major]], |
| 139 | + |
| 140 | + text(18pt, font: ("Times New Roman", "SimSun"))[*班 级:*], |
| 141 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#class]], |
| 142 | + |
| 143 | + text(18pt, font: ("Times New Roman", "SimSun"))[*姓 名:*], |
| 144 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#author]], |
| 145 | + |
| 146 | + text(18pt, font: ("Times New Roman", "SimSun"))[*学 号:*], |
| 147 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#student_id]], |
| 148 | + |
| 149 | + text(18pt, font: ("Times New Roman", "SimSun"))[*指导教师:*], |
| 150 | + u(width: 15em, offset: 0.35em)[#text(16pt)[#supervisor]], |
| 151 | + ) |
| 152 | + |
| 153 | + v(2cm) |
| 154 | + text(16pt)[#if date == "today" { datetime.today().display("[year]年[month]月[day]日") } else { date }] |
| 155 | + |
| 156 | + pagebreak() |
| 157 | + } |
| 158 | + |
| 159 | + // =========================== |
| 160 | + // 摘要页 |
| 161 | + // =========================== |
| 162 | + if show_abstract { |
| 163 | + set page(header: none, footer: none, numbering: none) |
| 164 | + set align(center) |
| 165 | + |
| 166 | + text(18pt, font: ("Times New Roman", "SimSun"))[*摘 要*] |
| 167 | + v(1.5em) |
| 168 | + |
| 169 | + set align(left) |
| 170 | + set par(first-line-indent: 0em) |
| 171 | + |
| 172 | + abstract |
| 173 | + v(2em) |
| 174 | + |
| 175 | + set par(first-line-indent: 0em) |
| 176 | + text(font: ("Times New Roman", "SimSun"))[*关键词:*] + keywords.join(";") |
| 177 | + |
| 178 | + pagebreak() |
| 179 | + } |
| 180 | + |
| 181 | + // =========================== |
| 182 | + // 正文页眉页脚设置 |
| 183 | + // =========================== |
| 184 | + set page( |
| 185 | + header: [ |
| 186 | + #grid( |
| 187 | + columns: (auto, 1fr), |
| 188 | + align: (left + top, right + top), |
| 189 | + gutter: 0.5em, |
| 190 | + image("template/assets/HFUT_badge_zh_Horizontal.svg", height: header_logo_height), |
| 191 | + [ |
| 192 | + #v(0.8em) |
| 193 | + #text(15pt, font: ("Times New Roman", "SimSun"))[*#title*] |
| 194 | + ], |
| 195 | + ) |
| 196 | + #v(-1.0em) |
| 197 | + #line(length: 100%, stroke: header_line_stroke) |
| 198 | + ], |
| 199 | + footer: context align(center)[ |
| 200 | + #text(10pt)[合肥工业大学 - 第 #counter(page).display("1") 页] |
| 201 | + ], |
| 202 | + numbering: "1", |
| 203 | + ) |
| 204 | + |
| 205 | + counter(page).update(1) |
| 206 | + |
| 207 | + // =========================== |
| 208 | + // 目录页 |
| 209 | + // =========================== |
| 210 | + // 居中显示目录标题 |
| 211 | + align(center)[ |
| 212 | + #text(18pt, font: ("Times New Roman", "SimSun"))[*目 录*] |
| 213 | + ] |
| 214 | + |
| 215 | + v(1.5em) |
| 216 | + |
| 217 | + outline( |
| 218 | + title: none, |
| 219 | + depth: 3, |
| 220 | + indent: auto, |
| 221 | + ) |
| 222 | + |
| 223 | + pagebreak() |
| 224 | + |
| 225 | + // =========================== |
| 226 | + // 标题样式配置 |
| 227 | + // =========================== |
| 228 | + // 设置标题自动编号 |
| 229 | + set heading(numbering: "1.1.1") |
| 230 | + |
| 231 | + show heading.where(level: 1): it => { |
| 232 | + // 一级标题:黑体加粗,视觉突出 |
| 233 | + set text(font: ("Times New Roman", "SimHei"), weight: "bold", size: 18pt) |
| 234 | + set align(center) |
| 235 | + |
| 236 | + v(0.5em) |
| 237 | + if it.numbering != none { |
| 238 | + block[#counter(heading).display() #it.body] |
| 239 | + } else { |
| 240 | + block[#it.body] |
| 241 | + } |
| 242 | + v(0.5em) |
| 243 | + } |
| 244 | + |
| 245 | + show heading.where(level: 2): it => { |
| 246 | + // 二级标题:宋体加粗,避免与一级标题冲突 |
| 247 | + set text(font: ("Times New Roman", "SimSun"), weight: "bold", size: 15pt) |
| 248 | + if it.numbering != none { |
| 249 | + block[#counter(heading).display() #it.body] |
| 250 | + } else { |
| 251 | + block[#it.body] |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + show heading.where(level: 3): it => { |
| 256 | + // 三级标题:宋体加粗,保持层次一致性 |
| 257 | + set text(font: ("Times New Roman", "SimSun"), weight: "bold", size: 13pt) |
| 258 | + if it.numbering != none { |
| 259 | + block[#counter(heading).display() #it.body] |
| 260 | + } else { |
| 261 | + block[#it.body] |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + // =========================== |
| 266 | + // 正文内容 |
| 267 | + // =========================== |
| 268 | + body |
| 269 | +} |
0 commit comments