2026-07-03,我写完了学生生涯的最后一篇实验报告🤓。这个模板总共产出了 64 份实验/作业报告,这里将其开源。示例文档可以查看上面的 Showcase。
Repordy 是一个面向实验报告和课程作业的 LaTeX 模板。模板以简洁的非衬线排版为主,支持中英混排、标题页、目录、参考文献、代码块、提示框、作业题目和常用图表排版,风格干净专业也具有一定 markdown-like 风格。
Get your Report Ready!
模板修改自 Sullivan Business Report 和 Lachaise Assignment,并加入了中文支持和丰富的组件。
report和homework两种文档样式。- 提供
\code{}行内代码、file、question、task、hint、warn、ghnote等定制化组件。 chinese选项,启用后会使用中文日期格式、图表名、目录名和 GB/T 7714-2015 参考文献风格,适合全中文文稿撰写。- 默认使用
biblatex + biber管理参考文献。 - 提供
.latexmkrc和.latexindent.yaml,方便统一编译和格式化。 - 内置 IBM Plex、HarmonyOS Sans SC、Source Han Serif CN 字体,无需额外安装系统字体。
先安装一个完整的 LaTeX 发行版
模板依赖 fontspec 和 xeCJK,不能使用 pdfLaTeX 编译。推荐使用 XeLaTeX,仓库中的 .latexmkrc 已设置为 xelatex -> biber -> xelatex 的自动编译流程。
常用命令行工具:
latexmk:自动编译主文档。biber:处理biblatex参考文献。latexindent:格式化.tex文件。
编辑根目录下的 main.tex,修改标题、作者信息和正文内容
\documentclass[
a4paper,
12pt,
templatestyle=report,
]{Repordy}
\addbibresource{references.bib}
\reporttitle[Short Title]{Report Title}
\reportsubtitle{Report Subtitle}
\reportauthors{Name Student ID\\\href{mailto:example@sjtu.edu.cn}{example@sjtu.edu.cn}}
\begin{document}
\makerepordytitle
\repordytableofcontents
\section{xxx}
Start writing here.
\repordybibliography
\end{document}然后在仓库根目录编译
latexmk main.tex如果需要强制重新编译
latexmk -g -xelatex -interaction=nonstopmode -file-line-error main.tex清理辅助文件
latexmk -c main.texexamples/ 目录中包含几个可参考的入口文件:
examples/report.tex:较短的实验报告示例。examples/homework.tex:较短的课程作业示例。examples/showcase.tex:完整功能展示,包含图、表、代码块、提示框、附录和更多排版组件。
PDF 预览可在 GitHub Pages 中查看。
编译示例时,建议在 examples/ 目录中显式使用根目录的 .latexmkrc:
cd examples
latexmk -r ../.latexmkrc showcase.tex示例文件位于子目录时,需要在 \documentclass 之前指定字体目录:
\newcommand{\repordyfontpath}{../fonts/}常用文档选项:
\documentclass[
a4paper,
12pt,
chinese,
templatestyle=report,
]{Repordy}templatestyle=report 是默认报告样式,包含标题页、目录、正文和参考文献。常用入口命令如下
\makerepordytitle
\repordytableofcontents
\repordybibliographytemplatestyle=homework 是作业样式,不生成大标题页、目录、参考文献和附录,第一页顶部会显示作业信息。作业题目可使用
\exercise{1.1}{题目标题}如果需要添加附录,将相应 section 包裹在 repordyappendices 环境中,会自动生成大写字母编号
\begin{repordyappendices}
\section{Appendix Section}
Appendix content.
\end{repordyappendices}chinese 选项适合中文文档,会将 Figure、Table、Listing、Contents、References、Exercise、of 等显示文本切换为中文或中文习惯写法,并使用 GB/T 7714-2015 参考文献风格。
unnumberedsections 选项会关闭章节编号。
报告样式常用命令:
\docdate{\repordytoday}
\rightheadercontent{\includegraphics[width=2.5cm]{_SJTU_char_.pdf}}
\titlelogo{\includegraphics[width=7.5cm]{_SJTU_logo_.pdf}}
\reporttitle[Short Title]{Long Report Title}
\reportsubtitle{Subtitle}
\reportauthors{Name Student ID\\\href{mailto:example@sjtu.edu.cn}{example@sjtu.edu.cn}}作业样式常用命令:
\docdate{\repordytoday}
\rightheadercontent{}
\homeworktitle[Homework 3]{Homework 3}
\homeworkcourse{Course Name}
\homeworkauthor{Your Name}
\homeworkauthorinfo{Stu ID: 0000000000}
\homeworkuniversity{Shanghai Jiao Tong University}图片默认会从 imgs/、../imgs/ 和当前目录查找,因此使用仓库内置图片时通常不需要写目录前缀。
在 references.bib 中添加参考文献,然后在入口文件中加载
\addbibresource{references.bib}正文中使用 biblatex 命令引用,例如
\autocite{vaswani2017attentionneed}文末使用
\repordybibliography仓库中的 references.bib 包含一些示例条目,其中部分来自 biblatex-gb7714-2015 的示例。
本项目使用 latexindent 格式化 LaTeX 源码,规则位于 .latexindent.yaml。VS Code 的 LaTeX Workshop 已在 .vscode/settings.json 中配置为读取该文件。默认缩进为 2 个空格,并会移除行尾空白。
命令行格式化:
latexindent -w -l=.latexindent.yaml main.tex
latexindent -w -l=.latexindent.yaml Repordy.cls
latexindent -w -l=.latexindent.yaml examples/report.tex在 VS Code 中,可使用 LaTeX Workshop 的格式化功能,例如 macOS 上的 Shift+Option+F。
macOS 上如果使用 TeX Live 或 MacTeX 自带的 latexindent,有时会遇到 Perl 模块缺失,例如:
Can't locate File/HomeDir.pm in @INC
推荐直接安装 Homebrew 版 latexindent:
brew install latexindent
latexindent --versionWindows 上通常可以使用 MiKTeX 或 TeX Live 附带的 latexindent。如果遇到 Perl 相关错误,推荐安装 Strawberry Perl,并确认 perl 和 latexindent 都在 PATH 中。
检查命令:
perl --version
latexindent --version字体文件已随仓库放在 fonts/ 目录中,模板默认从该目录加载字体,因此不需要把字体安装到系统字体目录。
默认字体配置为
- 英文无衬线:IBM Plex Sans。
- 英文衬线:IBM Plex Serif。
- 英文等宽:IBM Plex Mono。
- 中文无衬线与主字体:HarmonyOS Sans SC。
- 中文衬线/斜体搭配:Source Han Serif CN。
- 中文等宽搭配:HarmonyOS Sans SC,缩放为
0.95以更贴近 IBM Plex Mono 的视觉高度。
相关授权文件保留在 fonts/LICENSES/ 中。重新分发本模板或基于本模板的项目时,请遵循字体授权协议。
.
├── main.tex # 默认入口文件
├── Repordy.cls # 模板类文件
├── references.bib # 参考文献示例
├── .latexmkrc # latexmk 编译配置
├── .latexindent.yaml # latexindent 格式化配置
├── .vscode/settings.json # VS Code / LaTeX Workshop 配置
├── fonts/ # 内置字体和字体 license
├── imgs/ # 模板图片和示例图片
└── examples/ # 报告、作业和完整 showcase 示例
Repordy requires XeLaTeX or LuaLaTeX:当前使用了 pdfLaTeX。请改用 latexmk main.tex。
找不到字体或字体样式异常:确认 fonts/ 目录存在,并且入口文件相对目录正确。根目录入口通常无需额外设置;examples/ 下的入口文件需要在 \documentclass 前设置 \newcommand{\repordyfontpath}{../fonts/}。
参考文献没有更新:使用 latexmk main.tex,不要只运行一次 xelatex。本项目使用 biblatex + biber。
Can't locate File/HomeDir.pm in @INC:latexindent 调用的 Perl 缺少模块。macOS 推荐 brew install latexindent,Windows 推荐安装 Strawberry Perl。
本项目遵循 CC BY-NC-SA 4.0 协议。
IBM Plex 系列和 Source Han Serif CN 字体遵循 SIL Open Font License 1.1 协议,HarmonyOS Sans SC 字体遵循 HarmonyOS Sans Fonts License Agreement 协议。
上海交通大学校徽校名图片(_SJTU_char_.pdf、_SJTU_logo_.pdf)的版权归上海交通大学所有。示例文档中部分 logo 图片仅为测试和展示使用,本项目不具有其版权。