-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchap01.tex
More file actions
597 lines (438 loc) · 17.3 KB
/
chap01.tex
File metadata and controls
597 lines (438 loc) · 17.3 KB
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
% !TeX root = ../shcmthesis-example.tex
\part{\LaTeX{} 使用}
\chapter{\LaTeX{} 介绍}
\textbf{声明:以下文字节选复制自\url{https://oi-wiki.org/tools/latex/},并根据本文情况稍作修改}
\section{什么是 \LaTeX{}}
LaTeX(读作/ˈlɑːtɛx/或/ˈleɪtɛx/)是一个让你的文档看起来更专业的排版系统,而不是文字处理器。它尤其适合处理篇幅较长、结构严谨的文档,并且十分擅长处理公式表达。它是免费的软件,对大多数操作系统都适用。
LaTeX 基于 TeX(Donald Knuth 在 1978 年为数字化排版设计的排版系统)。TeX 是一种电脑能够处理的低级语言,但大多数人发现它很难使用。LaTeX 正是为了让它变得更加易用而设计的。目前 LaTeX 的版本是 LaTeX 2e。
如果你习惯于使用微软的 Office Word 处理文档,那么你会觉得 LaTeX 的工作方式让你很不习惯。Word 是典型的「所见即所得」的编辑器,你可以在编排文档的时侯查看到最终的排版效果。但使用 LaTeX 时你并不能方便地查看最终效果,这使得你专注于内容而不是外观的调整。
一个 LaTeX 文档是一个以 .tex 结尾的文本文件,可以使用任意的文本编辑器编辑,比如 Notepad,但对于大多数人而言,使用一个合适的 LaTeX 编辑器会使得编辑的过程容易很多。在编辑的过程中你可以标记文档的结构。完成后你可以进行编译——这意味着将它转化为另一种格式的文档。它支持多种格式,但最常用的是 PDF 文档格式。
\section{章节}
文档可以分为篇(Part)、章(Chatpers)、节(Sections)小节(Subsections)和小小节(Subsubsections),使用命令如下:
\begin{python}
\part{...}
\chapter{...}
\section{...}
\subsection{...}
\subsubsection{...}
\end{python}
\section{文字处理}
LaTeX 有多种不同的字体效果,在此列举一部分:
\begin{python}
\textit{words in italics}
\textsl{words slanted}
\textsc{words in smallcaps}
\textbf{words in bold}
\texttt{words in teletype}
\textsf{sans serif words}
\textrm{romanwords}
\underline{underlined words}
\end{python}
效果如下:
\textit{words in italics}
\textsl{words slanted}
\textsc{words in smallcaps}
\textbf{words in bold}
\texttt{words in teletype}
\textsf{sans serif words}
\textrm{romanwords}
\underline{underlined words}
其中,这些命令都可以通过快捷键打出,选中一句文字后按下快捷键即可,例如\textbackslash textit\{\} 为Ctrl+i,\textbackslash textbf\{\} 为Ctrl+b,
如果使用苹果电脑则将Ctrl替换为Command。
\section{段落}
\subsection{段落换行}
在LaTex中段落需要间隔一行以进行换行,例如:
\begin{python}
段落一
段落二
段落三
\end{python}
显示效果为:
段落一
段落二
段落三
\subsection{段落缩进}
LaTeX 默认每个章节第一段首行顶格,之后的段落首行缩进。如果想要段落顶格,在要顶格的段落前加 \noindent 命令即可。
\section{列表}
LaTeX 支持两种类型的列表:有序列表(enumerate)和无序列表(itemize)。列表中的元素定义为\textbackslash item。列表可以有子列表。
\rightarrow 输入下面的内容来生成一个有序列表套无序列表:
\begin{python}
\begin{enumerate}
\item First thing
\item Second thing
\begin{itemize}
\item A sub-thing
\item Another sub-thing
\end{itemize}
\item Third thing
\end{enumerate}
\end{python}
\rightarrow 编译并核对 PDF 文档。
列表长这样:
\begin{enumerate}
\item First thing
\item Second thing
\begin{itemize}
\item A sub-thing
\item Another sub-thing
\end{itemize}
\item Third thing
\end{enumerate}
可以使用方括号参数来修改无序列表头的标志。例如,\textbackslash item[-] 会使用一个杠作为标志,你甚至可以使用一个单词,比如 \textbackslash item[One]。
下面的代码:
\begin{python}
\begin{itemize}
\item[-] First thing
\item[+] Second thing
\begin{itemize}
\item[Fish] A sub-thing
\item[Plants] Another sub-thing
\end{itemize}
\item[Q] Third thing
\end{itemize}
\end{python}
生成的效果为:
\begin{itemize}
\item[-] First thing
\item[+] Second thing
\begin{itemize}
\item[Fish] A sub-thing
\item[Plants] Another sub-thing
\end{itemize}
\item[Q] Third thing
\end{itemize}
\section{注释和空格}
我们使用 \% 创建一个单行注释,在这个字符之后的该行上的内容都会被忽略,直到下一行开始。快捷键为Ctrl+/,若使用苹果电脑则为Command+/。
下面的代码:
\begin{python}
It is a truth universally acknowledged % Note comic irony
in the very first sentence ,
that a single man in possession of a good fortune,
must be in want of a wife.
\end{python}
生成的结果为:
It is a truth universally acknowledged % Note comic irony
in the very first sentence , that a single man in possession of a good fortune,
must be in want of a wife.
多个连续空格在 LaTeX 中被视为一个空格。多个连续空行被视为一个空行。空行的主要功能是开始一个新的段落。通常来说,LaTeX 忽略空行和其他空白字符,两个反斜杠(\textbackslash\textbackslash)可以被用来换行。
如果你想要在你的文档中添加空格,你可以通过添加~从而添加空格。
或者 \textbackslash vaspace\{...\} 的命令,这样可以添加竖着的空格,高度可以指定。如 \textbackslash vspace\{12pt\} 会产生一个空格,高度等于 12pt 的文字的高度。
\section{脚注}
在需要添加脚注的地方插入\textbackslash footnote{脚注内容},则会自动在页脚部分插入脚注内容。
例如:
\begin{python}
文字内容一\footnote{注释一}和文字内容二\footnote{注释二}
\end{python}
效果如下:
文字内容一\footnote{注释一}和文字内容二\footnote{注释二}
可以看到在本页底部已经自动按编号添加了注释内容。
\section{特殊字符}
下列字符在 LaTeX 中属于特殊字符:
\begin{python}
#
$
%
^
&
_
{
}
~
\
\end{python}
为了使用这些字符,我们需要在他们前面添加反斜杠进行转义:
\begin{python}
\#
\$
\%
\^{}
\&
\_
\{
\}
\~{}
\end{python}
\section{表格}
表格(tabular)命令用于排版表格,表应具有自明性。
\subsection{普通表格}
LaTeX 默认表格是没有横向和竖向的分割线的——如果你需要,你得手动设定。LaTeX 会根据内容自动设置表格的宽度。
下面的代码可以创一个表格:
\begin{python}
\begin{tabular}{...}
\end{tabular}
\end{python}
例如:
\begin{python}
\begin{center}
\begin{tabular}{|r|l|}
\centering
\hline
8 & here's \\
\cline 86 & stuff \\
\hline
\hline
2008 & now \\
\hline
\end{tabular}
\end{center}
\end{python}
效果如下:
\begin{center}
\begin{tabular}{|r|l|}
\hline
8 & here's \\
\cline{2-2}
86 & stuff \\
\hline
2008 & now \\
\hline
\end{tabular}
\end{center}
l 表示一个左对齐的列;
r 表示一个右对齐的列;
c 表示一个向中对齐的列;
| 表示一个列的竖线;
例如,\{lll\} 会生成一个三列的表格,并且保存向左对齐,没有显式的竖线;\{|l|l|r|\} 会生成一个三列表格,前两列左对齐,最后一列右对齐,并且相邻两列之间有显式的竖线。
表格的数据在 \textbackslash begin\{tabular\} 后输入:
\& 用于分割列;
\textbackslash \textbackslash 用于换行;
\textbackslash hline 表示插入一个贯穿所有列的横着的分割线;
\textbackslash cline\{1-2\} 会在第一列和第二列插入一个横着的分割线。
最后使用 \textbackslash end\{tabular\} 结束表格。
\subsection{三线表}
为使表格简洁易读,可以采用三线表,如表~\ref{tab:three-line}。
三条线可以使用 \pkg{booktabs} 宏包提供的命令生成。
例如:
\begin{python}
\begin{table}
\centering
\caption{三线表示例}
\begin{tabular}{ll}
\toprule
文件名 & 描述 \\
\midrule
shcmthesis.dtx & 模板的源文件,包括文档和注释 \\
shcmthesis.cls & 模板文件 \\
shcmthesis-*.bst & BibTeX 参考文献表样式文件 \\
\bottomrule
\end{tabular}
\label{tab:three-line}
\end{table}
\end{python}
效果如下:
\begin{table}
\centering
\caption{三线表示例}
\begin{tabular}{ll}
\toprule
文件名 & 描述 \\
\midrule
shcmthesis.dtx & 模板的源文件,包括文档和注释 \\
shcmthesis.cls & 模板文件 \\
shcmthesis-*.bst & BibTeX 参考文献表样式文件 \\
\bottomrule
\end{tabular}
\label{tab:three-line}
\end{table}
表格如果有附注,尤其是需要在表格中进行标注时,可以使用 \pkg{threeparttable} 宏包。
研究生要求使用英文小写字母 a、b、c……顺序编号,本科生使用圈码 ①、②、③……编号。
例如:
\begin{python}
\begin{table}
\centering
\begin{threeparttable}[c]
\caption{带附注的表格示例}
\label{tab:three-part-table}
\begin{tabular}{ll}
\toprule
文件名 & 描述 \\
\midrule
shcmthesis.dtx\tnote{a} & 模板的源文件,包括文档和注释 \\
shcmthesis.cls\tnote{b} & 模板文件 \\
shcmthesis-*.bst & BibTeX 参考文献表样式文件 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item [a] 可以通过 xelatex 编译生成模板的使用说明文档;
使用 xetex 编译 \file{shcmthesis.ins} 时则会从 \file{.dtx} 中去除掉文档和注释,得到精简的 \file{.cls} 文件。
\item [b] 更新模板时,一定要记得编译生成 \file{.cls} 文件,否则编译论文时载入的依然是旧版的模板。
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{python}
效果如下:
\begin{table}
\centering
\begin{threeparttable}[c]
\caption{带附注的表格示例}
\label{tab:three-part-table}
\begin{tabular}{ll}
\toprule
文件名 & 描述 \\
\midrule
shcmthesis.dtx\tnote{a} & 模板的源文件,包括文档和注释 \\
shcmthesis.cls\tnote{b} & 模板文件 \\
shcmthesis-*.bst & BibTeX 参考文献表样式文件 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item [a] 可以通过 xelatex 编译生成模板的使用说明文档;
使用 xetex 编译 \file{shcmthesis.ins} 时则会从 \file{.dtx} 中去除掉文档和注释,得到精简的 \file{.cls} 文件。
\item [b] 更新模板时,一定要记得编译生成 \file{.cls} 文件,否则编译论文时载入的依然是旧版的模板。
\end{tablenotes}
\end{threeparttable}
\end{table}
如某个表需要转页接排,可以使用 \pkg{longtable} 宏包,需要在随后的各页上重复表的编号。
编号后跟表题(可省略)和“(续)”,置于表上方。续表均应重复表头。
例如:
\begin{python}
\begin{longtable}{cccc}
\caption{跨页长表格的表题}
\label{tab:longtable} \\
\toprule
表头 1 & 表头 2 & 表头 3 & 表头 4 \\
\midrule
\endfirsthead
\caption*{续表~\thetable\quad 跨页长表格的表题} \\
\toprule
表头 1 & 表头 2 & 表头 3 & 表头 4 \\
\midrule
\endhead
\bottomrule
\endfoot
Row 1 & & & \\
Row 2 & & & \\
Row 3 & & & \\
Row 4 & & & \\
Row 5 & & & \\
Row 6 & & & \\
Row 7 & & & \\
Row 8 & & & \\
Row 9 & & & \\
Row 10 & & & \\
\end{longtable}
\end{python}
效果如下:
\begin{longtable}{cccc}
\caption{跨页长表格的表题}
\label{tab:longtable} \\
\toprule
表头 1 & 表头 2 & 表头 3 & 表头 4 \\
\midrule
\endfirsthead
\caption*{续表~\thetable\quad 跨页长表格的表题} \\
\toprule
表头 1 & 表头 2 & 表头 3 & 表头 4 \\
\midrule
\endhead
\bottomrule
\endfoot
Row 1 & & & \\
Row 2 & & & \\
Row 3 & & & \\
Row 4 & & & \\
Row 5 & & & \\
Row 6 & & & \\
Row 7 & & & \\
Row 8 & & & \\
Row 9 & & & \\
Row 10 & & & \\
\end{longtable}
\subsection{表格引用}
通过在表格中加入\textbackslash label\{tab\_name\}来定义表格名称,在文本中使用\textbackslash ref\{tab\_name\}来引用。
建议在\textbackslash ref前添加空格~以示美观。
例如:
\begin{python}
此处引用表~\ref{tab:longtable}。
\end{python}
效果为:
此处引用表~\ref{tab:longtable}。
\section{图片}
本章介绍如何在 LaTeX 文档中插入图片。
图片应当是 PDF,PNG,JPEG 或者 GIF 文件。
建议矢量图片使用 PDF 格式,比如数据可视化的绘图;
照片应使用 JPG 格式;
其他的栅格图应使用无损的 PNG 格式。
注意,LaTeX 不支持 TIFF 格式;EPS 格式已经过时。
\subsection{单张图片}
图片通常在 \env{figure} 环境中使用 \cs{includegraphics} 插入,如图~\ref{fig:example} 的源代码。
例如:
\begin{python}
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{example-image-a.pdf}
\caption*{国外的期刊习惯将图表的标题和说明文字写成一段,需要改写为标题只含图表的名称,其他说明文字以注释方式写在图表下方,或者写在正文中。}
\caption{示例图片标题}
\label{fig:example}
\end{figure}
\end{python}
效果如下:
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{example-image-a.pdf}
\caption*{国外的期刊习惯将图表的标题和说明文字写成一段,需要改写为标题只含图表的名称,其他说明文字以注释方式写在图表下方,或者写在正文中。}
\caption{示例图片标题}
\label{fig:example}
\end{figure}
[h] 是位置参数,h 表示把图表近似地放置在这里(如果能放得下)。有其他的选项:t 表示放在在页面顶端;b 表示放在在页面的底端;p 表示另起一页放置图表。你也可以添加一个 ! 参数来强制放在参数指定的位置(尽管这样排版的效果可能不太好)。
\textbackslash centering 将图片放置在页面的中央。如果没有该命令会默认左对齐。使用它的效果是很好的,因为图表的标题也是居中对齐的。
\textbackslash includegraphics\{...\} 命令可以自动将图放置到你的文档中,图片文件应当与 TeX 文件放在同一目录下。
width=1\textbackslash textwidth 是一个可选的参数,它指定图片的宽度——与文本的宽度相同。宽度也可以以厘米为单位。你也可以使用 [scale=0.5] 将图片按比例缩小(示例相当于缩小一半)。
\textbackslash caption\{...\} 定义了图表的标题。如果使用了它,LaTeX 会给你的图表添加「Figure」开头的序号。你可以使用 \textbackslash listoffigures 来生成一个图表的目录。
\textbackslash label\{...\} 创建了一个可以供你引用的标签。
若图或表中有附注,采用英文小写字母顺序编号,附注写在图或表的下方。
国外的期刊习惯将图表的标题和说明文字写成一段,需要改写为标题只含图表的名称,其他说明文字以注释方式写在图表下方,或者写在正文中。
\subsection{多个图片}
如果一个图由两个或两个以上分图组成时,各分图分别以 (a)、(b)、(c)...... 作为图序,并须有分图题。
推荐使用 \pkg{subcaption} 宏包来处理, 比如图~\ref{fig:multi-image}中的图~\ref{fig:subfig-a} 和图~\ref{fig:subfig-b}和。
例如:
\begin{python}
\begin{figure}
\centering
\subcaptionbox{分图 A\label{fig:subfig-a}}
{\includegraphics[width=0.35\linewidth]{example-image-a.pdf}}
\subcaptionbox{分图 B\label{fig:subfig-b}}
{\includegraphics[width=0.35\linewidth]{example-image-b.pdf}}
\caption{多个分图的示例}
\label{fig:multi-image}
\end{figure}
\end{python}
效果如下:
\begin{figure}
\centering
\subcaptionbox{分图 A\label{fig:subfig-a}}
{\includegraphics[width=0.35\linewidth]{example-image-a.pdf}}
\subcaptionbox{分图 B\label{fig:subfig-b}}
{\includegraphics[width=0.35\linewidth]{example-image-b.pdf}}
\caption{多个分图的示例}
\label{fig:multi-image}
\end{figure}
\subsection{图片引用}
通过在表格中加入\textbackslash label\{fig\_name\}来定义表格名称,在文本中使用\textbackslash ref\{fig\_name\}来引用。
建议在\textbackslash ref前添加空格~以示美观。
例如:
\begin{python}
此处引用图~\ref{fig:multi-image},及其图~\ref{fig:subfig-b}和图~\ref{fig:subfig-b}。
\end{python}
效果为:
此处引用图~\ref{fig:multi-image},及其图~\ref{fig:subfig-b}和图~\ref{fig:subfig-b}。
\section{谱例}
对于音乐类论文,常需要使用谱例。本模板提供了专门的 \env{score} 环境来处理谱例,用法与 \env{figure} 环境类似,但编号和标题使用「谱例」前缀。
例如:
\begin{python}
\begin{score}
\centering
\includegraphics[width=0.8\linewidth]{example-image-a.pdf}
\caption{示例谱例标题}
\label{score:example}
\end{score}
\end{python}
效果如下:
\begin{score}
\centering
\includegraphics[width=0.8\linewidth]{example-image-a.pdf}
\caption{示例谱例标题}
\label{score:example}
\end{score}
谱例的引用方式与图片相同,使用 \cs{ref\{score:example\}} 即可引用谱例~\ref{score:example}。
谱例清单可以使用 \cs{listofscores} 命令生成,用法与 \cs{listoffigures} 类似。