forked from sjtug/SJTUThesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjtuthesis.cls
501 lines (431 loc) · 15.5 KB
/
sjtuthesis.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
%==================================================
%% sjtuthesis.cls for SJTU Master Thesis
%% based on CASthesis.cls -- http://www.ctex.org/PackageCASthesis
%% Hosted on https://github.com/weijianwen/sjtu-thesis-template-latex
%% SJTU LaTeX Forum https://bbs.sjtu.edu.cn/bbsdoc,board,TeX_LaTeX.html
%% Encoding: UTF-8
%% ==================================================
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{sjtuthesis.cls}[2012/12/05 v0.5 sjtuthesis document class]
\newif\ifsjtu@typeinfo \sjtu@typeinfotrue
\DeclareOption{notypeinfo}{\sjtu@typeinfofalse}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{ctexbook}}
\ProcessOptions
\LoadClass[fancyhdr,fntef,UTF8,adobefonts]{ctexbook}[2005/11/25]
%% 导入 sjtuthesis.cfg 文件
\AtEndOfPackage{\makeatletter\input{sjtuthesis.cfg}\makeatother}
%% 当前模板的版本
\newcommand{\version}{\sjtu@value@templateversion}
% XeTeX Fonts
\RequirePackage{fontspec}
\RequirePackage{metalogo} % Some Logo
\setmainfont{TeX Gyre Termes}
%% 页边距设置
\oddsidemargin 1.5 true cm
\if@twoside
\evensidemargin 0 true cm
\else
\evensidemargin 1.5 true cm
\fi
\textheight 21 true cm
\textwidth 14.5 true cm
\headheight 15pt
\parskip 0.5ex plus 0.25ex minus 0.25ex
%% 上边距
\addtolength{\voffset}{-0.5cm}
%% Command -- Clear Double Page
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\thispagestyle{empty}%
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
%% 选择编译
\RequirePackage{ifthen}
%% check pdfTeX mode
\RequirePackage{ifpdf}
%% 复杂表格
\RequirePackage{threeparttable}
\RequirePackage{dcolumn}
\RequirePackage{multirow}
\RequirePackage{booktabs}
\newcolumntype{d}[1]{D{.}{.}{#1}}% or D{.}{,}{#1} or D{.}{\cdot}{#1}
%% Math Tools
\RequirePackage{mathtools,amsthm,amsfonts,amssymb,bm,mathrsfs}
\RequirePackage{upgreek}
%% 定义几个常用的数学常量符号
\newcommand{\me}{\mathrm{e}} %定义 对数常数e,虚数符号i,j以及微分算子d为直立体。
\newcommand{\mi}{\mathrm{i}}
\newcommand{\mj}{\mathrm{j}}
\newcommand{\dif}{\mathrm{d}}
% 可伸长的数学符号
\def\ExtendSymbol#1#2#3#4#5{\ext@arrow 0099{\arrowfill@#1#2#3}{#4}{#5}}
\def\RightExtendSymbol#1#2#3#4#5{\ext@arrow 0359{\arrowfill@#1#2#3}{#4}{#5}}
\def\LeftExtendSymbol#1#2#3#4#5{\ext@arrow 6095{\arrowfill@#1#2#3}{#4}{#5}}
\newcommand\myRightarrow[2][]{\RightExtendSymbol{=}{=}{\Rightarrow}{#1}{#2}}
\newcommand\myLeftarrow[2][]{\LeftExtendSymbol{\Leftarrow}{=}{=}{#1}{#2}}
\newcommand\myBioarrow[2][]{\ExtendSymbol{\Leftarrow}{=}{\Rightarrow}{#1}{#2}}
\newcommand\myLongEqual[2][]{\ExtendSymbol{=}{=}{=}{#1}{#2}}
% bullets in the item
\renewcommand\labelitemi{\ensuremath{\bullet}} % 原来定义为 \textbullet
% CJK-LaTeX Logo \CJKLaTeX
\newcommand{\CJKLaTeX}{CJK--\LaTeX}
%% graphics packages
\RequirePackage{graphicx}
%% 并列子图
\RequirePackage{subfigure}
%% 如果插入的图片没有指定扩展名,那么依次搜索下面的扩展名所对应的文件
\DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg,.jpeg}
% ccaption -- bicaption
\RequirePackage{ccaption}
\captiondelim{\ }
\captionnamefont{\kaishu\small}
\captiontitlefont{\kaishu\small}
%% sort and compress citations
\RequirePackage[sort&compress,numbers]{natbib}
% 上标引用
\newcommand{\upcite}[1]{\textsuperscript{\cite{#1}}}
% 将浮动参数设为较宽松的值
\renewcommand{\textfraction}{0.15}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.65}
\renewcommand{\floatpagefraction}{0.60}
% 定公式、图、表编号为"3-1"的形式,即分隔符由.变为短杠
\renewcommand\theequation{\arabic{chapter}--\arabic{equation}}
\renewcommand\thefigure{\arabic{chapter}--\arabic{figure}}
\renewcommand\thetable{\arabic{chapter}--\arabic{table}}
% 颜色宏包
\RequirePackage{xcolor}
%% 一些有趣的符号图案
\RequirePackage{marvosym}
\RequirePackage{wasysym}
% 中文破折号
\newcommand{\cndash}{\rule{0.0em}{0pt}\rule[0.35em]{1.4em}{0.05em}\rule{0.2em}{0pt}}
% listings 源代码显示宏包
\RequirePackage{listings}
\lstset{tabsize=4, %
frame=shadowbox, %把代码用带有阴影的框圈起来
commentstyle=\color{red!50!green!50!blue!50},%浅灰色的注释
rulesepcolor=\color{red!20!green!20!blue!20},%代码块边框为淡青色
keywordstyle=\color{blue!90}\bfseries, %代码关键字的颜色为蓝色,粗体
showstringspaces=false,%不显示代码字符串中间的空格标记
stringstyle=\ttfamily, % 代码字符串的特殊格式
keepspaces=true, %
breakindent=22pt, %
numbers=left,%左侧显示行号
stepnumber=1,%
numberstyle=\tiny, %行号字体用小号
basicstyle=\footnotesize, %
showspaces=false, %
flexiblecolumns=true, %
breaklines=true, %对过长的代码自动换行
breakautoindent=true,%
breakindent=4em, %
aboveskip=1em, %代码块边框
%% added by http://bbs.ctex.org/viewthread.php?tid=53451
fontadjust,
captionpos=t,
framextopmargin=2pt,framexbottommargin=2pt,abovecaptionskip=-3pt,belowcaptionskip=3pt,
xleftmargin=4em,xrightmargin=4em, % 设定listing左右的空白
texcl=true,
% 设定中文冲突,断行,列模式,数学环境输入,listing数字的样式
extendedchars=false,columns=flexible,mathescape=true
numbersep=-1em
}
\renewcommand{\lstlistingname}{\sjtu@value@listingname} %% 重命名Listings标题头
%% hyperref package
\ifxetex % xelatex
\RequirePackage[xetex]{hyperref}
\hypersetup{
bookmarksnumbered,%
colorlinks,%
linkcolor=blue,%
citecolor=blue,%
plainpages=false,%
pdfstartview=FitH
}
\fi
%% enumerate 列表环境间距调节
% Ref: http://bbs.ctex.org/viewthread.php?tid=52331&page=1
\RequirePackage{enumitem}
% \setenumerate[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=5pt}
% \setitemize[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
% \setdescription{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=5pt}
% 参考文献风格 GBT7714-2005
\bibliographystyle{GBT7714-2005NLang}
% sjtuspace
\newcommand\sjtuspace{\protect\CTEX@spaceChar\protect\CTEX@spaceChar}
\def\sjtu@getfileinfo#1 #2 #3\relax#4\relax{%
\def\sjtufiledate{#1}%
\def\sjtufileversion{#2}%
\def\sjtufileinfo{#3}}%
\expandafter\ifx\csname [email protected]\endcsname\relax
\edef\reserved@a{\csname ver@ctextemp_sjtuthesis.cls\endcsname}
\else
\edef\reserved@a{\csname [email protected]\endcsname}
\fi
\expandafter\sjtu@getfileinfo\reserved@a\relax? ? \relax\relax
\def\sjtu@underline[#1]#2{%
\CTEXunderline{\hbox to #1{\hfill#2\hfill}}}
\def\sjtuunderline{\@ifnextchar[\sjtu@underline\CTEXunderline}
\newcommand\classification[1]{\def\sjtu@value@classification{#1}}
\newcommand\studentnumber[1]{\def\sjtu@value@studentnumber{#1}}
\newcommand\confidential[1]{\def\sjtu@value@confidential{#1}}
\newcommand\UDC[1]{\def\sjtu@value@UDC{#1}}
\newcommand\serialnumber[1]{\def\sjtu@value@serialnumber{#1}}
\newcommand\school[1]{\def\sjtu@value@school{#1}}
\newcommand\degree[1]{\def\sjtu@value@degree{#1}}
\renewcommand\title[2][\sjtu@value@title]{%
\def\sjtu@value@title{#2}
\def\sjtu@value@titlemark{\MakeUppercase{#1}}}
\renewcommand\author[1]{\def\sjtu@value@author{#1}}
\newcommand\advisor[1]{\def\sjtu@value@advisor{#1}}
\newcommand\advisorinstitute[1]{\def\sjtu@value@advisorinstitute{#1}}
\newcommand\major[1]{\def\sjtu@value@major{#1}}
\newcommand\submitdate[1]{\def\sjtu@value@submitdate{#1}}
\newcommand\defenddate[1]{\def\sjtu@value@defenddate{#1}}
\newcommand\institute[1]{\def\sjtu@value@institute{#1}}
\newcommand\chairman[1]{\def\sjtu@value@chairman{#1}}
% “绘制”SJTU中文标题页
\renewcommand\maketitle[1]{%
\cleardoublepage
\thispagestyle{empty}
\begin{center}
\songti\zihao{-3}\sjtu@label@statement
\vskip \stretch{1}
{\heiti\zihao{3} \sjtu@value@title}
\vskip \stretch{1}
{\fangsong\zihao{4}}
\def\tabcolsep{1pt}
\def\arraystretch{1.5}
\begin{tabular}{lc}
\heiti\sjtu@label@author &\songti
\sjtuunderline[150pt]{\sjtu@value@author}
\\
\heiti\sjtu@label@studentnumber &\songti
\sjtuunderline[150pt]{\sjtu@value@studentnumber}
\\
\heiti\sjtu@label@advisor &\songti
\sjtuunderline[150pt]{\sjtu@value@advisor}
\\
\heiti\sjtu@label@major &\songti
\sjtuunderline[150pt]{\sjtu@value@major}
\\
\heiti\sjtu@label@defenddate &\songti
\sjtuunderline[150pt]{\sjtu@value@defenddate}
\end{tabular}
\end{center}
\vskip \stretch{0.5}
\clearpage
\if@twoside
\thispagestyle{empty}
\ifsjtu@typeinfo
\fi
\cleardoublepage
\fi
}
% English Title Page
\newcommand\englishtitle[1]{\def\sjtu@value@englishtitle{#1}}
\newcommand\englishauthor[1]{\def\sjtu@value@englishauthor{#1}}
\newcommand\englishadvisor[1]{\def\sjtu@value@englishadvisor{#1}}
\newcommand\englishschool[1]{\def\sjtu@value@englishschool{#1}}
\newcommand\englishinstitute[1]{\def\sjtu@value@englishinstitute{#1}}
\newcommand\englishdate[1]{\def\sjtu@value@englishdate{#1}}
\newcommand\englishdegree[1]{\def\sjtu@value@englishdegree{#1}}
\newcommand\englishmajor[1]{\def\sjtu@value@englishmajor{#1}}
% "绘制"英文标题页
\newcommand\makeenglishtitle[1]{%
\cleardoublepage
\thispagestyle{empty}
\begin{center}
{\normalfont\zihao{4} \sjtu@label@englishstatement}
\vspace*{20pt}
\vskip\stretch{1}
{\zihao{-1} \sjtu@value@englishtitle}
\vskip \stretch{1}
{\normalfont\zihao{4} \sjtu@value@englishauthor}
\vskip \stretch{1}
{\normalfont\zihao{4} \sjtu@label@englishadvisor}
\vskip 3pt
{\normalfont\zihao{4} \sjtu@value@englishadvisor}
\vskip \stretch{2}
\normalfont\normalsize \sjtu@value@englishinstitute
\vskip 30pt
\normalfont\normalsize \sjtu@value@englishdate
\vskip 20pt
\end{center}
\clearpage
\if@twoside
\thispagestyle{empty}
\cleardoublepage
\fi
}
% 原创性声明
\newcommand\makeDeclareOriginal{%
\cleardoublepage
\thispagestyle{empty}
\begin{center}
{\bf\zihao{3} \sjtu@value@school}\\
{\bf\zihao{3} \sjtu@label@original}
\end{center}
\vskip 10pt
{\zihao{-4}\sjtu@label@originalcontent}
\vskip 60pt
\hspace{13em}\sjtu@label@authorsign\hrulefill\hspace{1.5em}
\vskip 15pt
\hspace{16em}\sjtu@label@originalDate\hspace{1em}
\clearpage
\if@twoside
\thispagestyle{empty}
\cleardoublepage
\fi
}
% 授权声明
\newcommand\makeDeclareAuthorization{%
\cleardoublepage
\thispagestyle{empty}
\begin{center}
{\bf\zihao{3} \sjtu@value@school}\\
{\bf\zihao{3} \sjtu@label@authorization}
\end{center}
\vskip 10pt
{\zihao{-4} \sjtu@label@authorizationcontent}
\vskip 60pt
\sjtu@label@authorsign\hrulefill\hspace{3em}\sjtu@label@Supervisorsign\hrulefill
\vskip 15pt
\sjtu@label@originalDate\hfill\hspace{3em}\sjtu@label@originalDate
\clearpage
\if@twoside
\thispagestyle{empty}
\cleardoublepage
\fi
}
\pagestyle{fancy} {
\fancyhf{}
\fancyhead[LO, RE]{\small {\it \sjtu@value@school\sjtu@value@degree\sjtu@label@thesis}} % 奇数页左页眉和偶数页右页眉,即靠近书籍的页眉
\fancyhead[RO]{\small {\it \leftmark}} % 奇数页右页眉
\fancyhead[LE]{\small {\it \sjtu@value@titlemark}} % 偶数页左页眉
\fancyfoot[C]{\small ~---~{\bf\thepage}~---~} % 页脚
}
\fancypagestyle{plain} { % 设置开章页页眉页脚风格
\fancyhf{}
\fancyhead[LO,RE]{\small {\it \sjtu@value@school\sjtu@value@degree\sjtu@label@thesis}} % 奇数页左页眉和偶数页右页眉,即靠近书籍的页眉
\fancyhead[RO]{\small {\it \leftmark}} % 奇数页右页眉
\fancyhead[LE]{\small {\it \sjtu@value@titlemark}} % 偶数页左页眉
\fancyfoot[C]{\small ~---~{\bf\thepage}~---~} %页脚格式
}
% 中文摘要
\newenvironment{abstract}{\chapter[摘要]{\sjtu@value@title\vskip 20pt\sjtu@label@abstract}}{}
% 中文关键词
\newcommand\keywords[1]{\vspace{2ex}\noindent{\bf\large \sjtu@label@keywords} #1}
%_ 英文摘要
\newenvironment{englishabstract}{\chapter[ABSTRACT]{\sjtu@value@englishtitle\vskip 20pt\bfseries \sjtu@label@englishabstract}}{}
% _英文摘要
\newcommand\englishkeywords[1]{\vspace{2ex}\noindent{\bf\large \sjtu@label@englishkeywords} #1}
% 目录
\renewcommand\tableofcontents{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter{\contentsname}%目录里显示“目录”,否则\chapter*
\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
\addtocontents{toc}{\let\string\CTEX@spaceChar\relax}
%_ 参考文献环境
\renewenvironment{thebibliography}[1]
{\chapter{\bibname}%
\@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
\list{\@biblabel{\@arabic\c@enumiv}}%
{\settowidth\labelwidth{\@biblabel{#1}}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\@openbib@code
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\@arabic\c@enumiv}}%
\sloppy
\clubpenalty4000
\@clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode`\.\@m}
{\def\@noitemerr
{\@latex@warning{Empty `thebibliography' environment}}%
\endlist}
\newenvironment{publications}[1]
{\chapter{\sjtu@label@publications}%
\@mkboth{\MakeUppercase\sjtu@label@publications}
{\MakeUppercase\sjtu@label@publications}%
\list{\@biblabel{\@arabic\c@enumiv}}%
{\settowidth\labelwidth{\@biblabel{#1}}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\@openbib@code
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\@arabic\c@enumiv}}%
\sloppy
\clubpenalty4000
\@clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode`\.\@m}
{\def\@noitemerr
{\@latex@warning{Empty `publications' environment}}%
\endlist}
\newenvironment{projects}[1]
{\chapter{\sjtu@label@projects}%
\@mkboth{\MakeUppercase\sjtu@label@projects}
{\MakeUppercase\sjtu@label@projects}%
\list{\@biblabel{\@arabic\c@enumiv}}%
{\settowidth\labelwidth{\@biblabel{#1}}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\@openbib@code
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\@arabic\c@enumiv}}%
\sloppy
\clubpenalty4000
\@clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode`\.\@m}
{\def\@noitemerr
{\@latex@warning{Empty `projects' environment}}%
\endlist}
\newenvironment{resume}
{\chapter{\sjtu@label@resume}}
{}
\newenvironment{resumesection}[1]
{{\noindent\normalfont\bfseries #1}
\list{}{\labelwidth\z@
\leftmargin 2\ccwd}
\item\relax}
{\endlist}
\newenvironment{resumelist}[1]
{{\noindent\normalfont\bfseries #1}
\list{}{\labelwidth\z@
\leftmargin 4\ccwd
\itemindent -2\ccwd
\listparindent\itemindent}
\item\relax}
{\endlist}
\renewenvironment{thanks}
{\chapter{\sjtu@label@thanks}}
{}
\newenvironment{symbolnote}
{\chapter{\sjtu@label@symbolnote}}
{}
\setcounter{secnumdepth}{4} % 章节编号深度 (part 对应 -1)
\setcounter{tocdepth}{2} % 目录深度 (part 对应 -1)
\newtheoremstyle{break}% name
{}% Space above, empty = `usual value'
{}% Space below
{\itshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries}% Thm head font
{.}% Punctuation after thm head
{\newline}% Space after thm head: \newline = linebreak
{}% Thm head spec
\endinput
%%
%% End of file `sjtuthesis.cls'.