文章目錄
從這篇博客入門了LaTeX,這裏總結一下學習心得以及比較常用的東西。
LaTex文檔結構
一個簡單的LaTeX文檔的結構如下:
%% 從類似C語言中的導包,有什麼額外的功能都在這裏添加
\documentclass[UTF8]{ctexart} % 定義文章的格式、編碼
%% 有什麼額外的功能都在這裏添加
%% \begin{document}到\end{document}之間類似C語言中的main函數,屬於文章正文部分
\begin{document}
Hello world!
\end{document}
添加作者、標題、日期。
在latex的main函數之前添加這個部分,這裏title、author、date有點像函數。在正文中使用\maketitle調用就能顯示出來。
\documentclass[UTF8]{ctexart}
\title{你好,world!}
\author{Liam}
\date{\today}
\begin{document}
\maketitle % 使導言部分的title信息顯示出來
你好,world!
\end{document}
章節和段落
\section{hello}表示章標題1.hello。使用\section{}這個模塊會自動添加序號,所以不需要在{}中加序號。
\section{} %一級章標題
\subsection{} % 二級章標題
\subsubsection{} % 三級章標題
\paragraph{} % 段落:縮進兩格
\subparagraph{} % 段落:再縮進兩格
插入目錄
根據設置的章標題來劃分段落。
\tabelofcontents % 插入目錄,需要在maketitle下一行,否則title會被替換成目錄
插入數學公式
先要導入包,有兩種模式,類似markdown代碼嵌入的兩種模式:
- 和文字在一行(n人間)
- 另起一行(單人間)
\usepackage{amsmath} % 導入包
公式一開始不太熟的話,可以用一些在線的公式編輯器來輔助使用,比如:
https://private.codecogs.com/latex/eqneditor.php?lang=zh-cn
兩種插入模式
- 行內模式(inline):$公式 $
- 行間模式(display):[ 公式 ]
$E=mc^2$ % inline
\[ E=mc^2. \] % display
\begin{equation} % 帶標號的display模式
E=mc^2.
\end{equation}
上下標和空格
- 上標:
^
- 下標:
_
- 默認作用於後一個字符,要作用於多個字符使用
{}
括起來 - 空一個漢字格:
\quad
根式與分式
- 根式:\sqrt{根號裏的數}
- 分式:\frac{分子}{分母}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\sqrt{x}$, $\frac{1}{2}$.
\[ \sqrt{x}, \]
\[ \frac{1}{2}. \]
\end{document}
符號
行內和行間的分式是有差別的。行間的分式會隔得更開一些。
- 正負號:\pm\
- 叉乘:\times\
- 除法:\div\
- 點乘:\cdot\
- 交:\cap\
- 並:\cup\
- 大於等於(greater than or equal):\geq\
- 小於等於(less than or equal):\leq\
- 不等於(not equal):\neq\
- 約等於(approximate): \approx\
- 恆等於:\equiv\
- 累加:\sum_{i=1}^n i
- 累乘:\prod_{i=1}^n
積分就不多做介紹了。需要的時候查詢即可。
\[ \pm\; \times \; \div\; \cdot\; \cap\; \cup\;
\geq\; \leq\; \neq\; \approx \; \equiv \]
% 正負號、x乘、÷、點乘、∩、∪、大於等於、小於等於、不等於、約等於、恆等於
% 累加、累乘
$ \sum_{i=1}^n i$
$\quad \prod_{i=1}^n $
括號
- 小括號:
()
- 中括號:
[]
- 大括號:
\{\}
- 尖括號:
\langel \rangel
省略號
- … :
\dots
更小一點 相比\cdots - . . . :
\cdots
更大一點 相比\dots - 豎的三點:
\vdots
- 斜的三點:
\ddots
矩陣
% 以下都爲矩陣,就是矩陣的括弧不一樣
\[ \begin{pmatrix} a&b\\c&d \end{pmatrix} \quad % 圓括弧
\begin{bmatrix} a&b\\c&d \end{bmatrix} \quad % 方括弧
\begin{Bmatrix} a&b\\c&d \end{Bmatrix} \quad % 花括弧
\begin{vmatrix} a&b\\c&d \end{vmatrix} \quad % 豎線
\begin{Vmatrix} a&b\\c&d \end{Vmatrix} \] % 兩條豎線
插入圖片
這部分內容參考這個大佬的簡書
\documentclass{article}
\usepackage{graphicx} % 導包
\begin{document}
\begin{figure}[h] % h表示可以浮動
\centering % 居中
\includegraphics[width=0.8\textwidth]{a.jpg} %\includegraphics[圖片參數]{文件名}
\caption{name} % 圖片名字
\label{fun} %標籤,方便文章引用
\end{figure}
\end{document}
插入表格
插入表格使用這個網址,在線生成,感覺會比較快
http://www.tablesgenerator.com/
編輯器
離線編輯
我是用的Atom來編輯LaTex,需要安裝幾個插件,感覺還是比較方便的。
具體可以參考這個網址的教程安裝:https://www.cnblogs.com/schaepher/p/5934184.html
在線編輯
在線編輯器有個很出名的叫overleaf,上面有很多tex模板可以直接用,也比較方便。還可以和論文管理軟件Zotero一起搭配使用,妙哉妙哉。
分點 itemize
\begin{itemize}
\item a
\item b
\end{itemize}
結果如下:
參考文獻插入鏈接
顯示結果如圖所示:
導包
\usepackage{url}
bib文件寫法
@misc{bugsimportance,
title = {How to triage bugs},
author = {C. M. Penalver},
howpublished = {\url{https://wiki.ubuntu.com/Bugs/Importance}},
year = {2016},
}