Files
Latex_learning/learning_LaTeX.tex
2020-04-29 18:22:00 +08:00

366 lines
14 KiB
TeX
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
%!TEX program = xelatex
%表示用xelatex编译文件
\documentclass[a4paper]{ctexart}
\usepackage{array}
\usepackage{tabularx}
\usepackage{indentfirst}
\setlength{\parindent}{2em}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{graphicx}
\begin{document}
\title{标题页}
\author{Ryan\thanks{注脚}%
\and Fan\thanks{注脚}%
}
\date{\today}
\maketitle
\abstract
一般用于紧跟\textbackslash maketitle 命令之后介绍文档的摘要\par
中文\LaTeX{}排版。
\section{\LaTeX 排版文字}
{}分段\\换行\textbackslash\textbackslash\par
冒号``please press the `x' key.''\par
连字符-用来组成复合词,\\%
短破折号--用来连接数字表示范围,\\%
长破折号---用来连接单词\par
省略号\dots{}\ldots\par
波浪号~\par
强调\underline{文字,但是无法换行,}%
\uline{ulem 宏包解决了这一问题,它提供的 uline 命令能够轻松生成自动换行的下划线。}%
\emph{emph 命令用来将文字变为斜体以示强调。%
\emph{如果在本身已经用 emph 命令强调的文字内部嵌套使用 emph 命令,}%
内部则使用直立体文字。%
}\par
在合适的位置插入一个不会断行的空格Fig.~1, Ryan~Fan\par
断行\\[15pt]可以带可选参数 $\langle length\rangle$,用于在换行处向下增加垂直间距%
\newline{}或者newline命令不用带参数\par
\newpage 断页,在在双栏排版中只起到另起一栏的作用\par
断词 I think this is: supercalifragil\-isticexpialidocious. %
And I think this is: supercalifragilisticexpialidocious.\par
\newpage
\tableofcontents
\section[目录和页眉页脚]{章节}
\subsection{子章节}
\subsubsection{子子章节}
\paragraph{段落}
\subparagraph{子段落}
\section*{标题不带编号}
\addcontentsline{toc}{section}{标题不带编号}
\part{分块}
\section{交叉引用}
A reference to this subsection\label{sec:this} looks like: %
``see section~\ref{sec:this} on page~\pageref{sec:this}.''
\section{脚注和边注}
“天地玄黄,宇宙洪荒。日月盈昃,辰宿列张。”\footnote{出自《千字文》。}\par
\begin{tabular}{l}
\hline
有些情况下(比如在表格环境、各种盒子\\
内)使用 footnote 并不能正确生成脚\\
注。我们以分两步进行,先使用 \\
footnotemark 为脚注计数,再在合适\\
的位置用 footnotetext 生成脚注。\footnotemark\\
\hline
\end{tabular}
\footnotetext{出自《千字文》。}
\marginpar{\footnotesize 边注较窄,不要写过多文字,最好设置较小的字号。}
\section{特殊环境}
\subsection{列表}
有序列表
\begin{enumerate}
\item An item.
\begin{enumerate}
\item A nested item.\label{itref}
\item[*] A starred item.
\end{enumerate}
\item Reference(\ref{itref}).
\end{enumerate}
无序列表
\begin{itemize}
\item An item.
\begin{itemize}
\item A nested item.
\item[+] A `plus' item. + A plus item.
\item Another item. Another item.
\end{itemize}
\item Go back to upper level.
\end{itemize}
关键字环境
\begin{description}
\item[Enumerate] Numbered list.
\item[Itemize] Non-numbered list.
\end{description}
重定义无序列表的符号
\renewcommand{\labelitemi}{\dag}
\renewcommand{\labelitemii}{\ddag}
\begin{itemize}
\item First item
\begin{itemize}
\item Subitem
\item Subitem
\end{itemize}
\item Second item
\end{itemize}
重定义有序列表的符号
\renewcommand{\labelenumi}{\Alph{enumi}>}
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
\subsection{对齐环境}
center、flushleft 和 flushright 环境分别用于生成%
居中、左对齐和右对齐的文本环境。
\begin{center}
Centered text using a
\verb|center| environment.
\end{center}
\begin{flushleft}
Left-aligned text using a
\verb|flushleft| environment.
\end{flushleft}
\begin{flushright}
Right-aligned text using a
\verb|flushright| environment.
\end{flushright}
还可以用以下命令直接改变文字的对齐方式:
\centering
Centered text paragraph.\par
\raggedright
Left-aligned text paragraph.\par
\raggedleft
Right-aligned text paragraph.\par
\begin{flushleft}
center 等环境会在上下文产生一个额外间距,%
\textbackslash centering 等命令不产生,只是改变对齐方式。%
\end{flushleft}
\raggedright
比如在浮动体环境 table 或 figure 内实现居中对齐,%
\textbackslash centering 命令即可,没必要再用 center 环境。
\subsection{引用环境}
\begin{description}
\item[quote] 用于引用较短的文字,首行不缩进\\
Francis Bacon says:
\begin{quote}
Knowledge is power.
\end{quote}
\item[quotation] 用于引用若干段文字,首行缩进\\
《木兰诗》:
\begin{quotation}
万里赴戎机,关山度若飞。
朔气传金柝,寒光照铁衣。
将军百战死,壮士十年归。
归来见天子,天子坐明堂。
策勋十二转,赏赐百千强。......
\end{quotation}
\end{description}
\subsection{代码环境}
\begin{verbatim}
#include <iostream>
int main()
{
std::cout << "Hello, world!"
<< std::endl;
return 0;
}
\end{verbatim}
\begin{verbatim*}
for (int i=0; i<4; ++i)
printf("Number %d\n",i);
\end{verbatim*}
要排版简短的代码或关键字\textbackslash verb $\langle delim\rangle\langle code\rangle\langle delim\rangle$\par
$\langle delim\rangle$ 标明代码的分界位置,前后必须一致,除字母、空格或星号外,%
可任意选择使得不与代码本身冲突,习惯上使用 | 符号。\par
\verb|\LaTeX| \\
\verb+(a || b)+ \verb*+(a || b)+
\subsection{表格}
\subsubsection{列表格}
tabular 环境使用 $\langle column-spec\rangle$ 参数指定表格的列数以及每列的格式。\par
\begin{tabular}{lcr|p{6em}}
\hline
left & center & right & par box with fixed width\\
L & C & R & P\\
\hline
\end{tabular}\par
@ 格式可在单元格前后插入任意的文本,%
但同时它也消除了单元格前后额外添加的间距。\par
\begin{tabular}{@{} r@{:}lr @{}}
\hline
1 & 1 & one\\
11 & 3 & eleven\\
\hline
\end{tabular}\par
格式参数重复\par
\begin{tabular}{|*{5}{c|}*{2}{p{3em}|}}
\hline
one & two & three & four & five & Hello! \LaTeX & Hello!\\
1 & 2 & 3 & 4 & 5 & hello! & \LaTeX\\
\hline
\end{tabular}\par
辅助格式 > 和 <,用于给列格式前后加上修饰命令\par
\begin{tabular}{>{\itshape}r<{*}l}
%需要使用array宏包
\hline
italic & normal \\
column & column \\
\hline
\end{tabular}\par
\begin{tabular}{>{\centering\arraybackslash}p{16em}}
\hline
辅助格式甚至支持插入 \textbackslash centering 等%
命令改变 p 列格式的对齐方式,一般还要加额外的命令 %
\textbackslash arraybackslash 以免出错。\\
\hline
\textbackslash centering 等对齐命令会破坏表格环境里 %
\textbackslash\textbackslash 换行命令的定义,%
\textbackslash arraybackslash 用来恢复之。%
如果不加 \textbackslash arraybackslash 命令,%
也可以用 \textbackslash tabularnewline 命令%
代替原来的 \textbackslash\textbackslash 实现表格换行。\\
\hline
\end{tabular}\par
\LaTeX 本身提供了 tabular* 环境用来排版定宽表格,但是不太方便使用,%
比如要用到 @ 格式插入额外命令,令单元格之间的间距为 \textbackslash fill,%
但即使这样仍然有瑕疵:\par
\begin{tabular*}{14em}{@{\extracolsep{\fill}}|c|c|c|c|}
\hline
A & B & C & D \\
\hline
a & b & c & d \\
\hline
\end{tabular*}\par
tabularx 宏包为我们提供了方便的解决方案。它引入了一个 X 列格式,%
类似 p 列格式,不过会根据表格宽度自动计算列宽,多个X列格式平均分配列宽。%
X列格式也可以用 array 里的辅助 格式修饰对齐方式:\par
\begin{tabularx}{14em}{|*{4}{>{\centering\arraybackslash}X|}}
\hline
A & B & C & D \\
\hline
a & b & c & d \\
\hline
\end{tabularx}\par
\subsubsection{横线}
\textbackslash cline\{$\langle i-j\rangle$\} 用来绘制跨越部分单元格的横线:\par
\begin{tabular}{|c|c|c|}
\hline
4 & 9 & 2 \\ \cline{2-3}
3 & 5 & 7 \\ \cline{1-1}
8 & 1 & 6 \\
\hline
\end{tabular}\par
三线表由 booktabs 宏包 支持,它提供了 \textbackslash toprule、%
\textbackslash midrule 和 \textbackslash bottomrule %
命令用以排版三线表的三条线, 以及和 \textbackslash cline 对应的 %
\textbackslash cmidrule。除此之外,最好不要用其它横线以及竖线:\par
\begin{tabular}{cccc}
\toprule
& \multicolumn{3}{c}{Numbers} \\
\cmidrule{2-4}
& 1 & 2 & 3 \\
\midrule
Alphbet & A & B & C \\
Roman & I & II& III \\
\bottomrule
\end{tabular} \par
\subsubsection{合并单元格}
横向合并单元格较为容易,由 \textbackslash multicolumn\{$\langle n\rangle$\}\{$\langle column-spec\rangle$\}\{$\langle item\rangle$\} %
命令实现:\par
其中 $\langle n\rangle$ 为要合并的列数,$\langle column-spec\rangle$ 为合并单元格后的列格式,只允许出现一个 l/c/r 或 p 格式。%
如果合并前的单元格前后带表格线 |,合并后的列格式也要带 | 以使得表格的竖线一致。\par
形如 \textbackslash multicolumn\{1\}\{$\langle column-spec\rangle$\}\{$\langle item\rangle$\} %
的命令可以用来修改某一个单元格的列格式。\par
\begin{tabular}{|c|c|c|}
\hline
1 & 2 & Center \\
\hline
\multicolumn{2}{|c|}{3} & \multicolumn{1}{r|}{Right} \\
\hline
4 & \multicolumn{2}{c|}{C} \\
\hline
\end{tabular}\par
纵向合并单元格需要用到 multirow 宏包提供的 %
\textbackslash multirow\{$\langle n\rangle$\}\{$\langle width\rangle$\}\{$\langle item\rangle$\} 命令:\par
$\langle width\rangle$ 为合并后单元格的宽度,可以填 * 以使用自然宽度。\par
\begin{tabular}{ccc}
\hline
\multirow{2}{*}{Item} & \multicolumn{2}{c}{Value} \\
\cline{2-3}
& First & Second \\
\hline
A & 1 & 2 \\
\hline
\end{tabular}
\subsubsection{嵌套表格}
在单元格中嵌套一个小表格可 以起到``拆分单元格''的效果。\par
注意要用 \textbackslash multicolumn 命令配合 @\{\} %
格式把单元格的额外边距去掉,使得嵌套的表格线能和外层的表格线正确相连:\par
\begin{tabular}{|c|c|c|}
\hline
a & b & c \\
\hline
a & \multicolumn{1}{@{}c@{}|}
{\begin{tabular}{c|c}
e & f \\
\hline
e & f \\
\end{tabular}} & c \\
\hline
a & b & c \\
\hline
\end{tabular}\par
如果不需要为“拆分的单元格”画线,并且只在垂直方向“拆分”的话,makecell 宏包%
提供 的 \textbackslash makecell 命令是一个简单的解决方案:\par
\begin{tabular}{|c|c|}
\hline
a & \makecell{d1 \\ d2} \\
\hline
b & c \\
\hline
\end{tabular}
\subsubsection{行距控制}
\LaTeX 生成的表格看起来通常比较紧凑。%
修改参数 \textbackslash arraystretch 可以得到行距更加宽松 的表格:\par
\renewcommand\arraystretch{1.8}
\begin{tabular}{|c|}
\hline
Really loose \\
\hline
tabular rows. \\
\hline
\end{tabular}\par
另一种增加间距的办法是给换行命令 \textbackslash\textbackslash 添加可选参数,%
在这一行下面加额外的间距,适合用于在行间不加横线的表格:\par
\renewcommand\arraystretch{1}
\begin{tabular}{c}
\hline
Head lines \\[6pt]
tabular lines \\
tabular lines \\
\hline
\end{tabular}
\subsection{图片}
\LaTeX 本身不支持插图功能,需要由 graphicx 宏包辅助支持。\par
使用 \textbackslash includegraphics[$\langle options\rangle$]\{$\langle filename\rangle$\} 命令加载图片了:\par
其中 $\langle filename\rangle$ 为图片文件名,文件名有时需要使用相对路径或绝对路径。\par
\textbackslash graphicspath 命令,用于声明一个或多个图片文件存放的目录,%
使用这些目录里的图片时可不用写路径:\par
\textbackslash includegraphics 命令的可选参数 $\langle options\rangle$ 支持 %
$\langle key\rangle$=$\langle value\rangle$ 形式赋值,常用的参数如下:\par
\begin{tabular}{ll}
\hline
参数 & 含义 \\
\hline
width=$\langle width\rangle$ & 将图片缩放到宽度为$\langle width\rangle$ \\
height=$\langle height\rangle$ & 将图片缩放到高度为$\langle height\rangle$ \\
scale=$\langle scale\rangle$ & 将图片相对于原尺寸缩放$\langle scale\rangle$\\
angle=$\langle angle\rangle$ & 令图片逆时针旋转$\langle angle\rangle$\\
\hline
\end{tabular}
\includegraphics[scale=0.1]{/home/ryan/Pictures/wallpaper/heic2007a}
\graphicspath{{/home/ryan/Pictures/wallpaper/}}
\includegraphics[scale=0.1]{heic1501a}
\appendix
\section{附录}
\end{document}