4 語法 Cheatsheet

下文許多內容直接自 Bookdown 擷取。想完整了解者,請閱讀 Bookdown 中的內容。

4.1 章節連結

4.1.1 錨點定義

在內文中,可以使用特殊語法建立前往其它章節的連結,但首先每個章節需要有錨點。若章節標題由英數組成,例如 ## Experimental Design, 則錨點會自動被定義成 experimental-design。若標題含有中文,例如 ## 實驗設計 則需自行定義錨點## 實驗設計 {#exp-design}

4.1.2 內文連結

要在內文建立連至其它章節的連結,需使用 \@ref(anchor) 的語法,例如,

  • 連結至 ## Experimental Design
    • \@ref(experimental-design)
  • 連結至 ## 實驗設計 {#exp-design}
    • \@ref(exp-design)

4.2 數學

4.2.1 Unnumbered Equations

\begin{equation*} 
\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x)
\end{equation*} 

\[\begin{equation*} \frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x) \end{equation*}\]

4.2.2 Numbered Equations

\begin{equation} 
  f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
  (\#eq:bino)
\end{equation} 

\@ref(eq:bino)

\[\begin{equation} f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k} \tag{1} \end{equation}\]

(1)

4.2.3 Multi-line Aligned Equations

\begin{equation} 
\begin{split}
\mathrm{Var}(\hat{\beta}) & =\mathrm{Var}((X'X)^{-1}X'y)\\
 & =(X'X)^{-1}X'\mathrm{Var}(y)((X'X)^{-1}X')'\\
 & =(X'X)^{-1}X'\mathrm{Var}(y)X(X'X)^{-1}\\
 & =(X'X)^{-1}X'\sigma^{2}IX(X'X)^{-1}\\
 & =(X'X)^{-1}\sigma^{2}
\end{split}
(\#eq:var-beta)
\end{equation}

詳見公式 \@ref(eq:var-beta)

\[\begin{equation} \begin{split} \mathrm{Var}(\hat{\beta}) & =\mathrm{Var}((X'X)^{-1}X'y)\\ & =(X'X)^{-1}X'\mathrm{Var}(y)((X'X)^{-1}X')'\\ & =(X'X)^{-1}X'\mathrm{Var}(y)X(X'X)^{-1}\\ & =(X'X)^{-1}X'\sigma^{2}IX(X'X)^{-1}\\ & =(X'X)^{-1}\sigma^{2} \end{split} \tag{2} \end{equation}\]

詳見公式 (2)

4.2.4 定理與證明

```{theorem, thm-label, name="Pythagorean theorem"}
For a right triangle, if $c$ denotes the length of the hypotenuse
and $a$ and $b$ denote the lengths of the other two sides, we have

$$a^2 + b^2 = c^2$$
```

詳見定理 \@ref(thm:thm-label)
Theorem 1 (Pythagorean theorem) For a right triangle, if \(c\) denotes the length of the hypotenuse and \(a\) and \(b\) denote the lengths of the other two sides, we have \[a^2 + b^2 = c^2\]

詳見定理 1