Latex不快速入門的入門
此文件是在B站學習劉海洋老師的LATEX入門教程的一些學習筆記。
命令
\cmd[opt]{arg1}{arg2}
\frac{1}{2}
環境
\begin
{
env
}
。。。。
\end
{
env
}
Latex的矩陣
\begin
{
martix
}
\\
。。。
\end
{
martix
}
右對齊
\begin
{
flushright
}
。。。
\end
{
flushright
}
正文文字
直接輸入正文文字 用空格分開單詞。 一個換行符等同於一個空格,多個空格效果與一個相同 自然段分段是空一行。
正文符號
\#
\$
\%
\&
\{
\}
\textbackslash
反斜線
% 鍵盤上沒有的符號用命令輸入
\S
\dag
\ddag
\P
\copyright
\textbullet
\textregistered
\texttrademark
\pounds
更多的符號輸入可以透過cmd `texdoc symbols` 檢視
數學公式
數學模式下字型、符號、間距與正文都不同,一切數學公式(包括單個符號n,Π)都要在數學模式下輸入。
行內公式(inline):使用一對符號$$表示。如
$a+b=c$
顯示公式(display)
簡單的不編號公式用命令\ [ 和 \ ]標示
基本的編號的公式使用
equation
環境
更加複雜的結構,使用
amsmath
宏包提供的專門的數學環境
上標與下標:
^ 和 _
上下劃線與花括號:
\overline,\underline,\overbrace,\underbrace
分式:
\frac{分子}{分母}
根式:
\sqrt[次數]{根號下}
矩陣:使用
amsmath
宏包提供的專門的矩陣環境
matrix,pmatrix,bmatrix
等。
特別複雜的矩陣(如帶線條)使用
array
環境作為表格畫出。
amsmath
是基本的數學工具包,在包含數學公式的文件中幾乎無處不在。
mathtools
則對
amsmath
做了一些補充和加強。
科學計算功能
%siunitx 宏包
\num
{
-1。235e96
}
\SI
{
299792458
}{
m/s
}
\SI
{
2x7x3。5
}{
m
}
\begin
{
tabular
}{
|S|
}
\hline
-234532
\\
13。55
\\
。9e37km
\\
\hline
\end
{
tabular
}
%chemformula 編寫化學式
\ch
{
2 H2 + O2 -> 2 H2O
}
\\
\ch
{
2H2O-> 2H2
^
+ O2
^}
列表環境
enumerate 編號
itemize 不編號
description 有標題
定理類環境
\newtheorem
定義定理類環境,如
\newtheorem{thm}{定理}[section]
\begin
{
thm
}
一個定理
\end
{
thm
}
\section
{
節
}
詩歌或引文
verse
quote
quotation
抄錄程式碼
\verb
\verb|#include
verbatim
\begin{verbatim}
#include
int main() {
puts(“hello world”); }
\end{verbatim}
高階程式碼:語法高亮
使用listings宏包
minted宏包(呼叫Pygment)
% 使用listings宏包
\begin{lstlisting}[language=C,basicstyle=\ttfamily,stringstyle=\color{blue}]
#include
int main() {
puts(“hello world”);
}
\end{lstlisting}
演算法結構
clrscode
宏包(演算法導論)
algorithm2e
宏包
algorithmicx
宏包的
algpseudocode
格式
% \usepackage{clrscode}
\begin
{
codebox
}
\Procname
{
$
\proc
{Merge
-
Sort}
(
A,p,r
)
$
}
\li
\If
$
p $ \li \Then $ q \gets \lfloor ( p + r )/ 2 \rfloor $ \li $ \proc {Merge - Sort} ( A,p,q ) $ \li $ \proc {Merge - Sort} ( A,q + 1 ,r ) $ \li $ \proc {Merge - Sort} ( A,p,q,r ) $ \End \end { codebox } 圖表與浮動環境 使用 tabular 環境 \begin { tabular }{ |rr| } \hline 輸入 & 輸出 \\ \hline $ - 2 $ & 4 \\ 0 & 0 \\ 2 & 4 \\ \hline \end { tabular } 同時可以使用一些工具生成表格程式碼 https://www。tablesgenerator。com/latex_tables 功能各異的表格宏 單元格處理: multirow 、makecell 長表格: longtable、xtab 定寬表格: xtabular 表線控制: booktabs、diagbox、arydshln 表列格式: array 綜合應用: tabu 插圖 graphicx 宏包 \includegraphics[width=2cm]{pkulogo。pdf} 浮動體 figure環境 table環境 其他環境可以使用 float 宏包獲得 浮動體標題使用 \caption 命令獲得,自動編號 自動化工具 hyperref :pdf的連結與書籤 宏包 設定文件格式 使用宏包 格式控制 字型字號 字型 \rmfamily,\textrm{。。。} \sffamily,\textsf{。。。} \ttfamily,\texttt{。。。} 字號: \Huge, \LARGE, \Large, \large, \normalszie, \small, \footnotesize, \scriptsize, \tiny 中文字號: \zihao{5} 、 \zihao{-3} 對齊 \centering、\raggedleft、\raggedright 空白間距 hspace{2cm} 水平 vspace{3cm} 垂直 版面佈局 宏包 geometry fancyhdr 分頁斷行 \linebreak、\\、\pagebreak、\newpage、\clearpage、\cleardoublepage 盒子 mbox{內容} \parbox{4em}{內容} minipage 格式應用於文件 使用在導言區單獨設定格式 直接設定相關引數 設定 \parindent、\parskip、\linespread、\pagestyle 修改部分命令定義。 如修改 \thesection、\labelenumi、\descriptionlabel、\figurename 利用工具宏包完成設定。 如使用 ctex 宏包設定中文格式,使用 tocloft 宏包設定目錄格式 利用自定義命令和環境 \newcommand\prg[1]{\textbf{\Huge #1}} \prg{sort}很有用