-
Notifications
You must be signed in to change notification settings - Fork 2
/
YNUbachelor.cls
509 lines (437 loc) · 16.3 KB
/
YNUbachelor.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
% Copyright
% GitHub repository:https://github.com/Astro-Lee/YNU-thesis-bachelor
% 作者:Rui-Zhi Li
% 邮箱:[email protected]
\newcommand\thesisversion{v0.0.1}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{YNUbachelor}[2021/12/24 YNU-thesis-bachelor \thesisversion, [email protected]]
\LoadClass[twoside,UTF8,a4paper,scheme=plain,zihao=-4,fontset=none]{ctexart}
%判断是否使用XeLaTeX编译
\RequirePackage{ifxetex}
\ifxetex\else
\ClassError{YNUbachelor}{必须使用 `xelatex' 编译器进行编译\MessageBreak Please choose `xelatex'}{Just choose `xelatex', no `pdflatex' or `latex' and so on.}
\fi
%标题以外,正文文字行距为固定值22pt
%https://github.com/ustctug/ustcthesis/blob/df62a2627f42556ab421700577e3b90af3947189/ustcthesis.cls#L647
\renewcommand\normalsize{%
\@setfontsize\normalsize{12bp}{22bp}%
\abovedisplayskip 12bp \@plus3bp \@minus7bp%
\abovedisplayshortskip \z@ \@plus3bp%
\belowdisplayshortskip 6.5bp \@plus3.5bp \@minus3bp%
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}%
\linespread{1}\selectfont
\normalsize
%\RequirePackage{ifplatform}
%字体下载 https://gitee.com/Astro-Lee/fonts
\RequirePackage{xeCJK}
%简体中文 宋体
%\setCJKmainfont{SimSun.ttf}[Path=fonts/]
\setCJKmainfont{SimSun.ttf}[AutoFakeBold=true, Path=fonts/, Mapping=fullwidth-stop]
%简体中文 黑体
\setCJKsansfont{SimHei.ttf}[Path=fonts/]
\newCJKfontfamily[heiti]\heiti{SimHei.ttf}[Path=fonts/]
%简体中文 仿宋
\setCJKmonofont{SimFang.ttf}[Path=fonts/]
%英文衬线字体 Serif
\setmainfont{TimesNewRoman-Regular.ttf}[%
Path=fonts/,
BoldFont=TimesNewRoman-Bold.ttf,
ItalicFont=TimesNewRoman-Italic.ttf,
BoldItalicFont=TimesNewRoman-BoldItalic.ttf,
]
%英文无衬线字体 Sans Serif
\setsansfont{Helvetica-Regular.ttf}[%
Path=fonts/,
BoldFont=Helvetica-Bold.ttf,
ItalicFont=Helvetica-Oblique.ttf,
BoldItalicFont=Helvetica-BoldOblique.ttf,
]
%英文等宽字体 Monospace
\setmonofont{CourierNew-Regular.ttf}[%
Path = fonts/,
BoldFont=CourierNew-Bold.ttf,
ItalicFont=CourierNew-Italic.ttf,
BoldItalicFont=CourierNew-BoldItalic.ttf,
Scale = MatchLowercase,
]
\RequirePackage{amsmath,amsfonts,amssymb,siunitx}%数学公式扩展,花体,扩展符号的基础字体支持,扩展符号定义成命令,物理量的单位
%\RequirePackage[math-style=ISO, bold-style=ISO]{unicode-math}
%\setmathfont{XITS Math}
%字体格式设置
\newcommand{\yiCengBiaoTi}{\zihao{3} \heiti}%一层标题格式设置
\newcommand{\erCengBiaoTi}{\zihao{4} \heiti}%二层标题格式设置
\newcommand{\otherFontSize}{\zihao{-4} \heiti}%三层及以下标题格式设置
%页边距设置
\RequirePackage[a4paper,
top=2.5cm,
bottom=2.0cm,
left=3.0cm,
right=2.0cm]{geometry}
\addtolength{\oddsidemargin}{0cm}
\addtolength{\evensidemargin}{1cm}
%ctexset设置
\ctexset{
tocdepth=3,%目录深度
secnumdepth=3,%section深度, 仅section, subsection, subsubsection可用
punct=quanjiao,%全角标点
autoindent=2,
today=small,
contentsname={目\texorpdfstring{\quad}{}录},
listfigurename={图目录},
listtablename={表目录},
figurename={图},
tablename={表},
abstractname={摘\texorpdfstring{\quad}{}要},
indexname={索引},
appendixname={附录},
bibname={参考文献},
proofname={证明},
}
\ctexset{
section = {
format ={\clearpage\phantomsection\centering\yiCengBiaoTi},
afterindent=true,
beforeskip={0.8em},
afterskip={0.5em},
fixskip = {false},
},
subsection = {
format ={\phantomsection\erCengBiaoTi},
afterindent=true,
beforeskip={0.5em},
afterskip={0.0em},
fixskip = {false},
},
subsubsection = {
format ={\phantomsection\otherFontSize},
afterindent=true,
beforeskip={0.5em},
afterskip={0.0em},
indent= {2\ccwd},
fixskip = {false},
},
}
%详细设置参见%https://zhuanlan.zhihu.com/p/401538511
%\RequirePackage{titlesec}%深度定制标题
%covers封面
%https://zhuanlan.zhihu.com/p/19734756
\RequirePackage{eso-pic}%插入封面
\RequirePackage{setspace}%行距控制
\def\school#1{\gdef\@school{#1}}%定义学院
\def\@school{\@latex@warning{No \noexpand\school given}}%如果没有提供机构命令,系统将会给出警告信息
\def\studentID#1{\gdef\@studentID{#1}}%定义学号
\def\@studentID{\@latex@warning{No \noexpand\studentID given}}%如果没有提供机构命令,系统将会给出警告信息
\def\major#1{\gdef\@major{#1}}%定义专业
\def\@major{\@latex@warning{No \noexpand\major given}}%如果没有提供机构命令,系统将会给出警告信息
\def\teacher#1{\gdef\@teacher{#1}}%定义指导教师
\def\@teacher{\@latex@warning{No \noexpand\teacher given}}%如果没有提供机构命令,系统将会给出警告信息
\newcommand{\frontcover}{%
\AddToShipoutPicture*{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]%
{figures/frontcover.pdf}
\vfill}}
\put(7.7cm,13cm){\makebox[18em][c]{\large \@title}}
\put(7.7cm,11.75cm){\makebox[18em][c]{\large \@school}}
\put(7.7cm,10.49cm){\makebox[18em][c]{\large \@major}}
\put(7.7cm,9.21cm){\makebox[18em][c]{\large \@author}}
\put(7.7cm,7.93cm){\makebox[18em][c]{\large \@studentID}}
\put(9.05cm,6.73cm){\makebox[15em][c]{\large \@teacher}}
\put(8.4cm,3.2cm){%
\makebox[2em][c]{\large \number\year}\hskip2em
\makebox[3.6em][c]{\large \number\month}\hskip1em
\makebox[3.6em][c]{\large \number\day}}
}
\pagestyle{empty}~\clearpage
}
%封底
\newcommand{\backcover}{
\AtEndDocument{%
\clearpage~\thispagestyle{empty}
\AddToShipoutPicture*{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]%
{figures/backcover.pdf}
\vfill}}
}
}}
%毕业论文(设计)独创性声明及使用授权
\newcommand{\copyrightpage}{%
\begin{center}
\heiti \zihao{3}毕业论文(设计)独创性声明及使用授权
\end{center}\vskip 2em
{
本毕业论文(设计)是作者在导师指导下取得的成果。除了文中特别加以标注和致谢的地方外,论文(设计)中不包含其他人已经发表或撰写过的研究成果,不存在剽窃或抄袭行为。与作者一同工作的同志对本研究所做的任何贡献均已在论文中作了明确的说明并表示了谢意。
现就论文(设计)的使用对云南大学授权如下:学校有权保留本论文(设计)(含电子版),也可以采用影印、缩印或其他复制手段保存论文(设计)\,;学校有权公布论文的全部或部分内容,可以将论文(设计)用于查阅或借阅服务;学校有权向有关机构送交学位论文(设计)用于学术规范审查、社会监督或评奖;学校有权将学位论文(设计)的全部或部分内容录入有关数据库用于检索服务。
%\hskip 1em {\heiti (内部或保密的论文}(设计){\heiti 在解密后应遵循此规定)}
\vskip 3.6cm
\noindent 作者姓名:\underline{\makebox[8em][c]{}} 导师姓名:\underline{\makebox[8em][c]{}}日 \hskip 1em 期:\underline{\makebox[8em][c]{}}
}
\pagestyle{empty}\clearpage}
%maketitle设置
\def\@maketitle{%
\null
\begin{center}
{\yiCengBiaoTi \@title}
\vskip 1em
{\zihao{-3} \@author}
\vskip 1em
{\zihao{-3} \@date}
\end{center}
\par
\vskip 1em
\pagenumbering{roman}
\global\let\school\relax
\global\let\@school\@empty
\global\let\studentID\relax
\global\let\@studentID\@empty
\global\let\major\relax
\global\let\@major\@empty
\global\let\teacher\relax
\global\let\@teacher\@empty
}%题名完成后,将系统内部和外部不再用到的的题名信息命令废止或清空,也就是说这些命令只能使用一次
%页眉页脚
\RequirePackage{lastpage}
\RequirePackage{fancyhdr}
\fancypagestyle{PreContent}{
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand\headrulewidth{0.0pt}
}
\fancypagestyle{Content}{
\fancyhf{}
\fancyhead[OC]{\zihao{5} \leftmark}
\fancyhead[EC]{\zihao{5} \@title}
\fancyfoot[C]{\zihao{5} 第\thepage 页(共~\pageref{LastPage}~页)}
\renewcommand\headrulewidth{0.5pt}
}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
% \renewcommand{\sectionmark}[1]{\markboth{\CTEXifname{\CTEXthesection\quad}{}#1}{}}
\setlength{\headheight}{12.64723pt}%页眉高度
%中英abstract, keywords设置
\renewenvironment{abstract}[1]{%
\section*{\abstractname
\addcontentsline{toc}{section}{\abstractname}
\markboth{\abstractname}{}
}
#1}
{\thispagestyle{PreContent}\pagenumbering{Roman}}
\newcommand{\keywords}[1]{%
{{\heiti 关键词:} #1}}
\newcommand{\enabstractname}{Abstract}
\newenvironment{enabstract}[1]{%
\section*{\bfseries \enabstractname
\addcontentsline{toc}{section}{\enabstractname}
\markboth{\enabstractname}{}
}
#1}
{\thispagestyle{PreContent}}
\newcommand{\enkeywords}[1]{%
{\textbf{Key Words:} #1}}
%contents目录设置
%http://static.latexstudio.net/article/2019/0513/titlesec_c.pdf
\RequirePackage{titletoc}%深度定制目录
\RequirePackage{afterpage}%用于目录后切换页眉页脚,https://gitee.com/MkSwQi/usstthesis/blob/master/usstthesis.cls#L347
\titlecontents{section}[\z@]{\heiti}
{\contentspush{\thecontentslabel\unskip\hspace{\ccwd}}}{}
{\titlerule*[.8pc]{$\cdot$}\contentspage}
\titlecontents{subsection}[2\ccwd]{}
{\contentspush{\thecontentslabel\hspace{\ccwd}}}{}
{\titlerule*[.8pc]{$\cdot$}\contentspage}
\titlecontents{subsubsection}[4\ccwd]{}
{\contentspush{\thecontentslabel\hspace{\ccwd}}}{}
{\titlerule*[.8pc]{$\cdot$}\contentspage}
\renewcommand\tableofcontents{%
\section*{\contentsname%
\addcontentsline{toc}{section}{\contentsname}%
\markboth{\contentsname}{}%
}%
\pagestyle{PreContent}
\@starttoc{toc}%
\thispagestyle{PreContent}%
\afterpage{\pagenumbering{arabic}}%
\pagestyle{Content}%
}
%acknowledgement致谢设置
\newcommand{\acknowledgementname}{致\texorpdfstring{\quad}{}谢}
\newenvironment{acknowledgement}[1]{%
\section*{\acknowledgementname
\addcontentsline{toc}{section}{\acknowledgementname}
\markboth{\acknowledgementname}{}
}
#1}
{}
%参考文献
\RequirePackage[square,numbers,super,sort&compress,sectionbib]{natbib}
%\RequirePackage{gbt7714}
\bibliographystyle{references/gbt7714-numerical.bst}%gbt7714-author-year,gbt7714-numerical
%natbib.sty
\renewcommand\bibsection{%
\section*{\refname%
\addcontentsline{toc}{section}{\refname}%
\markboth{\refname}{}%
}%
}
%https://github.com/ustctug/ustcthesis/blob/f7db43e2b87bf5f61babdd3a500ecbc69a803b3e/ustcthesis.cls#L3031
\renewcommand{\bibfont}{\normalsize}
\setlength{\bibsep}{0\p@ \@plus.2\p@}
\renewcommand\@biblabel[1]{[#1]\hfill}
\setlength{\bibhang}{2\ccwd}
%附录设置
\renewcommand\appendix{\par
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\renewcommand\thesection{\appendixname~\Alph{section}}
\renewcommand\thesubsection{\Alph{section}.\arabic{subsection}}
\renewcommand\thesubsubsection{\Alph{section}.\arabic{subsection}.\arabic{subsubsection}}
\renewcommand{\theequation}{\Alph{section}.\arabic{equation}}
\renewcommand{\thefigure}{\Alph{section}.\arabic{figure}}
\renewcommand{\thetable}{\Alph{section}.\arabic{table}}
}
%表格字号为五号,https://www.zhihu.com/question/366803177
\RequirePackage{xpatch}
\xpatchcmd\@floatboxreset
{\normalsize}
{\expandafter\ifstrequal\expandafter{\@captype}{table}
% if inside "table" env
{\small}
% otherwise
{\normalsize}}
{}{\fail}
\RequirePackage{etoolbox}%对浮动体无效
\AtBeginEnvironment{tabular}{\small}
\AtBeginEnvironment{longtable}{\small}
%图表的序号和标题间空一格,标题为黑体小四\otherFontSize
\RequirePackage[tableposition=bottom,figureposition=top,labelsep=quad]{caption}%图表标题
\RequirePackage{subcaption}%子图表标题
\DeclareCaptionFont{heiti}{\otherFontSize}
\captionsetup{labelfont=heiti,textfont=heiti}
\captionsetup[figure]{labelformat=simple}
\captionsetup[subfigure]{labelformat=parens}
\captionsetup[table]{labelformat=simple}
\captionsetup[subtable]{labelformat=parens}
%脚注为带圈数字https://github.com/CasperVector/pkuthss/blob/b80742e3c67bc5837dbb6c057a42b834315e9ced/tex/pkuthss.cls#L132
\RequirePackage{tikz}
\newcommand*{\@circled}[1]{%
\scalebox{0.5}{%
\tikz[thick, baseline = (char.base)]{%
\node[shape = circle, draw = black, minimum size = 1.25em, inner sep = 0pt ] (char) {\bfseries #1};
}}%
}
% Use circled numbers as footnote symbols. Does not affect title page, but
% footnote is rarely used in dissertation covers ;)
\renewcommand*{\thefootnote}{%
$^{\protect\@circled{\arabic{footnote}}}$%
}
% Provides utility to modify footnote spacing.
% Option used to make sure it does not render interleaf pages totally blank.
\RequirePackage[cleardoublepage = current]{scrextend}
% Set up footnote spacing: whole paragraph indent 2em, 0.1em after mark.
\deffootnote{2em}{0pt}{\thefootnotemark\hspace{0.1em}}
%https://zhuanlan.zhihu.com/p/74515148
% shorten footnote rule
% \xpatchcmd\footnoterule
% {.4\columnwidth}
% {1in}
% {}{\fail}
%列表环境间隔
%https://blog.csdn.net/fandroid/article/details/54644966
\RequirePackage{enumitem}
\setenumerate[1]{itemsep=-3pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
\setitemize[1]{itemsep=-3pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
\setdescription{itemsep=-3pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
%其他设置
\date{\today}
\RequirePackage{xcolor}%颜色
\RequirePackage{graphicx}%插入图片
\graphicspath{{figures/}}
\RequirePackage{zhlipsum}
\def\equationautorefname~#1\null{式\,(#1)\,\null}
\def\figureautorefname~#1\null{图\,#1\,\null}
\def\tableautorefname~#1\null{表\,#1\,\null}
\RequirePackage{listings}
\renewcommand{\lstlistingname}{代码片段}
\renewcommand{\lstlistlistingname}{代码片段目录}
%http://latexcolor.com/
\lstdefinelanguage{latex}{
basicstyle=\small\ttfamily,%整体格式设置
backgroundcolor=\color[RGB]{247, 247, 247},
%字符列为非等宽
flexiblecolumns=true,
%换行缩进
tabsize=4,
showtabs=false,
%代码框, 四个角, 框线宽
frame=single,
frameround=tttt,
%framerule=0pt,
%断行
breaklines=true,
breakindent=0pt,
breakatwhitespace=false,
%允许的空行数,大于1的空行将被省略,但行号仍被计算
emptylines=*1,
%行号
numbers=left,
numbersep=6pt,
numberstyle=\tiny\color[RGB]{102, 102, 102},
numberblanklines=false,
%stepnumber=2,
%展示空格
showspaces=false,
showstringspaces=false,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%LaTeX language 设置
%定义注释
morecomment=[l]{\%},
commentstyle={\color[RGB]{63, 127, 127}},
%环境 开始与结束
morekeywords={[1]begin,end},
keywordstyle={[1]\color{blue!70!black}\bfseries},
%导言区命令
morekeywords={[2]documentclass,usepackage},
keywordstyle={[2]\color{red!75!black}\bfseries},
%类和包
morekeywords={[3]YNUbachelor,myPackages},
keywordstyle={[3]\color[RGB]{119, 158, 203}\bfseries},
%个人信息
morekeywords={[4]title,school,author,studentID,major,teacher},
keywordstyle={[4]\color{red!80}\bfseries},
%命令名
morekeywords={[5]frontcover,copyrightpage,maketitle,tableofcontents,keywords,enkeywords,bfseries,textbf,lstinputlisting,centering,includegraphics,linewidth,caption,label,toprule,midrule,bottomrule,autoref,cite,reference,backcover,newcommand,newenvironment,renewcommand,renewenvironment,LaTeX,appendix,lstinline,heavyrulewidth,lightrulewidth,cmidrulewidth,cmidrule,verb,item,lstset,vspace,hspace,subcaption},
keywordstyle={[5]\color{cyan!70!black}\bfseries},
%环境名
morekeywords={[6]document,abstract,enabstract,figure,table,tabular,align,acknowledgement,latexcode,minipage,enumerate,itemize,subfigure},
keywordstyle={[6]\color[RGB]{90, 79, 207}\bfseries},
%章节
morekeywords={[7]section,subsection,subsubsection},
keywordstyle={[7]\color[RGB]{201, 105, 35}\bfseries},
}
\lstnewenvironment{latexcode}
{\lstset{language=latex,numbers=none}}
{}
%hyperref超链接设置
\AtEndOfClass{
\RequirePackage{hyperref}
\hypersetup{
breaklinks=true,
unicode=true,
linktoc=all,
bookmarksopen=true,
bookmarksnumbered=true,
pdfstartview=FitH,
pdftitle={云南大学本科毕业论文(设计)},
pdfauthor = \@author,
pdfcreator={YNU-thesis-bachelor \thesisversion},
}
% \pkg{hyperref} 与 \pkg{unicode-math} 存在一些兼容性问题, https://github.com/ustctug/ustcthesis/blob/bb27361648d850831d3899f308f7e2a83b9a6914/ustcthesis.cls#L3163
\@ifpackagelater{hyperref}{2019/04/27}{}{%
\g@addto@macro\psdmapshortnames{\let\mu\textmu}%
}
}