# LaTeX Tutorial
###### tags: `Tutorial`
###### author: `Jia-Wei, Liao`
## 註冊 Overleaf
* [Overleaf 網站](https://www.overleaf.com/)
## 基本模板
```
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsthm} %AMS數學套件%
\begin{document}
%%%%%%%%%%%%%%%%%%%% 可以開始打字 %%%%%%%%%%%%%%%%%%%%
This is a example.
\end{document}
```
#### Remark
% 為 LaTeX 的註解,不會進行編譯
## 基本數學指令
通常一般文字會打 x (正體),而數學變數會打成 $x$ (斜體)
數學模式要在指令的前後加上 `$`,指令前面要加 `\`
* **希臘字母:** `$\alpha$` $\to$ $\alpha$
* **三角函數:** `$\sin x$` $\to$ $\sin x$
* **次方:** `$a^b$` $\to$ $a^b$
* **下標:** `$a_n$` $\to$ $a_n$
* **分數:** `$\frac{1}{2}$` $\to$ $\frac{1}{2}$
* **根號:** `$\sqrt{2}$` $\to$ $\sqrt{2}$; `$\sqrt[3]{2}$` $\to$ $\sqrt[3]{2}$
* **極限:** `$\lim$` $\to \lim$
* **累積:** `$\sum$` $\to$ $\sum$
* **積分:** `$\int$` $\to$ $\int$
* **因為:** `$\because$` $\to$ $\because$
* **所以:** `$\therefore$` $\to$ $\therefore$
* **箭頭:** `$\to$` $\to$ $\to$
* **小於等於:** `\leq` $\to$ $\leq$
* **大於等於:** `\geq` $\to$ $\geq$
#### Remark
* 更多指令請參考 [LaTeX符號指令](https://drive.google.com/file/d/1eUTzNATdPz7Xm2dK6HF-oqRfgBsd5EaP/view)
* 覺得數學式子太小可以用 `\displaystyle` 來調整
#### Exercise
* $ax^2+bx+c$
:::spoiler 顯示答案
`$ax^2+bx+c$`
:::
* $x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$
:::spoiler 顯示答案
`$x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$`
:::
* $\log_a(x+y)= \log_ax+\log_ay$
:::spoiler 顯示答案
`$\log_a(x+y)= \log_ax+\log_ay$`
:::
* $\int_a^b f(x) dx=F(b)-F(a)$
:::spoiler 顯示答案
`$\int_a^b f(x) dx=F(b)-F(a)$`
:::
* $\displaystyle \lim_{x \to a} f(x) = f(a)$
:::spoiler 顯示答案
`$\displaystyle \lim_{x \to a} f(x) = f(a)$`
:::
* $\displaystyle \sum_{k=1}^n k^2=\frac{n(n+1)(2n+1)}{6}$
:::spoiler 顯示答案
`$\displaystyle \sum_{k=1}^n k^2=\frac{n(n+1)(2n+1)}{6}$`
:::
* $|a+b| \leq |a|+|b|$
:::spoiler 顯示答案
`$|a+b| \leq |a|+|b|$`
:::
## 空格
* `\,`
* `\quad`
* `\hspace{1cm}`
* `\noindent` : 開頭不空兩格
## 程式碼
```
\usepackage{listings}
\usepackage{xcolor}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=MATLAB,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=3,
backgroundcolor=\color{gray!2}
}
```
```
\begin{lstlisting}
## your code
\end{lstlisting}
```
## Beamer基本模板
- [官網基本模板](https://www.overleaf.com/learn/latex/Beamer)
```
\documentclass{beamer}
\title{Sample title}
\author{Anonymous}
\institute{Overleaf}
\date{2021}
\begin{document}
\frame{\titlepage}
\begin{frame}
\frametitle{Sample frame title}
This is some text in the first frame.
This is some text in the first frame.
This is some text in the first frame.
\end{frame}
\end{document}
```
## 更改主題
```
\usetheme{Madrid}
```
## 特殊指令
| 指令 | 編譯 |
| -------- | -------- |
| `0 \stackrel{a}{\longrightarrow} 1` | $0\stackrel{a}{\longrightarrow}1$ |
|`{n \choose i}` | ${n \choose i}$ |
|`{{\text {iid} \atop \sim} \atop}`| ${{\text {iid} \atop \sim}\atop}$|