LaTeX 基本使用篇
之前在寫推甄的研究計畫時,經由老師的推薦,開始使用overleaf,一款方便排版的線上軟體。這次想要簡單有系統性地學習一下,怎麼使用LaTeX這些語法,以及排版的方法等等。
有興趣的夥伴還請留步~~
Outline:
- 基本語法
- 基本用法
- 換行、縮排、字體調整、段落宣告
- 項目符號、表格
- 數學符號
- 統整範例
1. 基本語法
Latex也可以視為另一種程式語言,他們也有自己規則,由\
開頭。
[]
,中括號內為「選擇性參數」,可以省略。
{}
,大括號內的參數則是「不能省略」。
%
,註解符號
2. 基本用法
在LaTeX最上面的那行總會看見幾個常見的語法,這邊就為大家簡單介紹他們所帶表的意義。
\documentclass{article}
,和LaTeX說明使用哪一種格式,這邊代表的是article格式。
\documentclass[param]{format}
[format] 可以設定為 article, report, book, slides, letter等。
[param],則可以設置內文的字體、紙張的排版等等。
\documentclass[12pt, a4paper, twocolumn]{article}
\begin{document}
\end{document}
- preamble(前文):專門用來宣告會影響整個文稿的指令,也可以是設定標題、作者、日期的區域。以下範例宣告了本文件的版面配置。
\begin{document}
:正文開始\end{document}
:正文結束
\documentclass{article}% Preamble %
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6in, 10in}]{geometry}
\title{Practice}
\author{}
\date{October 2022}% 正文開始 %\begin{document}\section{Introduction}\end{document}
3. 換行、縮排、字體調整、段落宣告
換行:
\\
or\newline
縮排:
基本上default都會幫忙縮排,當不想縮排時,可以使用\noindent
。
字體調整:
粗體:\bg{text}
義大利花體:\it{text}
斜體:\sl{text}
還有很多其他字體,還請大家自行去發掘~~
字型大小:
段落宣告
\chapter
: Level 0
\section
:Level 1
\subsection
:Level 2
\subsubsection
:Level 3
\paragraph
:Level 4
\subparagraph
:Level 5
上面的Level指的是大小等級。
4. 項目符號、表格
項目符號 — 1:
\begin{itemize}
\item AAA
\item BBB
\begin{itemize}
\item CCC
\item DDD
\begin{itemize}
\item EEE
\item FFF
\end{itemize}
\end{itemize}
\end{itemize}
項目符號 — 2:
\begin{enumerate}
\item AAA
\item BBB
\begin{enumerate}
\item CCC
\item DDD
\begin{enumerate}
\item EEE
\item FFF
\end{enumerate}
\end{enumerate}
\end{enumerate}
表格:
\begin{tabular}[t]{|l|l|l|}
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
how are you
\begin{tabular}[t]{|l|l|l|}
:首先[t]
代表top,也可以是[b],button [c],center
如果後面還有其他文章或圖片的話,可以和其他文字、圖表進行排版,如上圖。\begin{tabular}[c]{|l|l|l|}
:[c]
代表center,文字就會對齊於表格的中間。
\hline
:畫雙橫線,本身會自動換行,因此不用再額外加上換行符號。
下面有三個範例,相信多看看範例,應該也會比較有感覺吧(差異之處,請看粗體的部分)
Example1:
\begin{tabular}[c]{lll} % l: left
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
Example2:
\begin{tabular}[c]{|r|r|r|} % r: right, |: 隔線
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
Example3:
\begin{tabular}[t]{|c|c|c|} % c: center, |: 隔線
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
5. 數學符號
inline mode: 在文字中夾雜數學符號。
The equation $x + 2y = 3$
Math Display mode: 比較長的數學式
\[ 數學式子 ]\\begin{equation} 數學式子 \end{equation}
Example1:
\[
\sum_{i=1}^{n}{n^2-3n+4} = f(n)
\]_表示下標,^表示上標。
Example2:
\begin{equation*} % *代表不使用編號
\sum_{i=1}^{n}{n^2-3n+4} = f(n)
\end{equation*} \\\begin{equation}
\sum_{i=1}^{n}{n^2-3n+4} = f(n)
\end{equation}
對齊模式(Aligned Mode)
\begin{aligned}
x_{1}^{(k+1)} = \frac{1}{a_{11}}(b_{1} - \sum_{j < 1}{a_{1j}x_{j}^{(k+1)}} - \sum_{j >
1}{a_{1j}x_{j}^{(k)}}) \\x_{2}^{(k+1)} = \frac{1}{a_{22}}(b_{2} - \sum_{j < 2}{a_{2j}x_{j}^{(k+1)}} - \sum_{j >
2}{a_{2j}x_{j}^{(k)}}) \\x_{3}^{(k+1)} = \frac{1}{a_{33}}(b_{3} - \sum_{j < 3}{a_{3j}x_{j}^{(k+1)}} - \sum_{j >
3}{a_{3j}x_{j}^{(k)}}) \\x_{4}^{(k+1)} = \frac{1}{a_{44}}(b_{4} - \sum_{j < 4}{a_{4j}x_{j}^{(k+1)}} - \sum_{j >
4}{a_{4j}x_{j}^{(k)}})\end{aligned}
\]
frac
: 分數sum
: sigma符號
其他常用符號
矩陣
重點: &
來區隔欄位, \\
來換行。
話不多說,直接丟幾個範例來熟悉熟悉。
Example1:
\[
A =
\left(
\begin{array}{clr} % clr: center, left, right
t_{11} & t_{12} & t_{13} \\
t_{21} & t_{22} & t_{23} \\
t_{31} & t_{32} & t_{33}
\end{array}
\right)
\]
Example2:
\[
\begin{array}{clcr}
a+b+c & uv & x-y & 27 \\
a+b & u+v & z & 134 \\
a & 3u+v & xyz & 2950
\end{array}
\]
Example3:
在preamble的部分,宣告 \usepackage{amsmath}
後,可以簡化後面寫矩陣的過程。
\usepackage{amsmath}
\[
\begin{pmatrix}
7 & -2 & 1 & 2 \\
2 & 8 & 3 & 1 \\
-1 & 0 & 5 & 2 \\
0 & 2 & -1 & 4
\end{pmatrix}
\begin{pmatrix}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{pmatrix}
=
\begin{pmatrix}
3 \\
-2 \\
5 \\
4
\end{pmatrix}
\]
統整範例
趁還有空閒時間的時候好好紀錄,之後可能只能用到什麼查到哪了~~
那我們就下次再見囉!掰掰 👋👋