# Tham Khảo Nhanh LaTeX

*Cấu trúc tài liệu, toán học, bảng biểu, hình ảnh*

> Source: LaTeX Documentation (overleaf.com/learn) · MIT

## Cấu Trúc Tài Liệu

### Khung Cơ Bản

```
\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{My Document}
\author{Your Name}
\date{\today}

\begin{document}
\maketitle
Content here.
\end{document}
```

### Loại Tài Liệu

| Command | Description |
|---------|-------------|
| `article` | Bài báo, tài liệu ngắn |
| `report` | Báo cáo có chương |
| `book` | Sách với phần và chương |
| `beamer` | Trình chiếu (slide) |
| `letter` | Thư từ |

## Cấu Trúc Văn Bản

### Tiêu Đề Phần

```
\part{Part Title}
\chapter{Chapter}       % report/book only
\section{Section}
\subsection{Subsection}
\subsubsection{Sub-sub}
\paragraph{Paragraph}
```

### Định Dạng Văn Bản

| Command | Description |
|---------|-------------|
| `\textbf{text}` | In đậm |
| `\textit{text}` | In nghiêng |
| `\underline{text}` | Gạch chân |
| `\texttt{text}` | Font monospace |
| `\emph{text}` | Nhấn mạnh (ngữ cảnh) |
| `\textsc{text}` | Chữ hoa nhỏ |

### Danh Sách

```
\begin{itemize}
  \item First item
  \item Second item
\end{itemize}

\begin{enumerate}
  \item Numbered item
  \item Second item
\end{enumerate}

\begin{description}
  \item[Term] Definition
\end{description}
```

## Toán Học

### Toán Trong Dòng & Khối

```
Inline: $e = mc^2$ or \(e = mc^2\)

Display:
\[ \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} \]

Numbered equation:
\begin{equation}
  E = mc^2
\end{equation}
```

### Ký Hiệu Toán Phổ Biến

| Command | Description |
|---------|-------------|
| `^{n} / _{n}` | Số mũ / chỉ số dưới |
| `\frac{a}{b}` | Phân số |
| `\sqrt{x} / \sqrt[n]{x}` | Căn bậc hai / căn bậc n |
| `\sum_{i=1}^{n}` | Ký hiệu tổng |
| `\int_{a}^{b}` | Ký hiệu tích phân |
| `\lim_{x \to 0}` | Giới hạn |
| `\infty` | Vô cực |
| `\alpha \beta \gamma \pi` | Chữ cái Hy Lạp |

### Môi Trường Align

```
\begin{align}
  f(x) &= x^2 + 2x + 1 \\
       &= (x + 1)^2
\end{align}
```

## Bảng Biểu

### Bảng Cơ Bản

```
\begin{tabular}{|l|c|r|}
  \hline
  Left & Center & Right \\
  \hline
  a & b & c \\
  d & e & f \\
  \hline
\end{tabular}
```

### Chỉ Định Cột

| Command | Description |
|---------|-------------|
| `l / c / r` | Căn trái / giữa / phải |
| `\|` | Đường kẻ dọc |
| `p{3cm}` | Cột độ rộng cố định với wrap |
| `\hline` | Đường kẻ ngang |
| `\multicolumn{n}{c}{text}` | Ô trải qua n cột |

### Float Bảng

```
\begin{table}[ht]
  \centering
  \caption{My Table}
  \label{tab:mytable}
  \begin{tabular}{ll}
    \hline
    Col1 & Col2 \\
    \hline
    a & b \\
    \hline
  \end{tabular}
\end{table}
```

## Hình Ảnh

### Chèn Hình

```
\usepackage{graphicx}   % in preamble

\includegraphics[width=0.8\textwidth]{image.png}
\includegraphics[scale=0.5]{figure.pdf}
```

### Float Hình

```
\begin{figure}[ht]
  \centering
  \includegraphics[width=0.7\textwidth]{plot.png}
  \caption{This is the caption.}
  \label{fig:myplot}
\end{figure}
```

### Tùy Chọn Vị Trí

| Command | Description |
|---------|-------------|
| `h` | Tại vị trí hiện tại (nếu có thể) |
| `t` | Đầu trang |
| `b` | Cuối trang |
| `p` | Trang riêng cho floats |
| `!` | Buộc vị trí (bỏ qua giới hạn) |

## References & Links

### Cross-References

```
\label{sec:intro}      % place marker
See Section~\ref{sec:intro}
Figure~\ref{fig:myplot} on page~\pageref{fig:myplot}
```

### Bibliography

```
\cite{knuth1984}        % inline citation
\bibliographystyle{plain}
\bibliography{refs}     % refs.bib file

% BibTeX entry:
@book{knuth1984,
  author  = {Knuth, Donald},
  title   = {The TeXbook},
  year    = {1984}
}
```

### Hyperlinks

```
\usepackage{hyperref}
\href{https://example.com}{Link Text}
\url{https://example.com}
```

## Packages Phổ Biến

### Packages Cần Thiết

| Command | Description |
|---------|-------------|
| `amsmath / amssymb` | Môi trường và ký hiệu toán học nâng cao |
| `graphicx` | Chèn và thay đổi kích thước hình ảnh |
| `geometry` | Lề và kích thước trang |
| `hyperref` | Hyperlinks và PDF metadata |
| `booktabs` | Bảng chất lượng cao với toprule/midrule |
| `listings` | Định dạng code với syntax highlight |
| `tikz` | Vẽ đồ họa và sơ đồ |
| `babel` | Hỗ trợ ngôn ngữ quốc tế hoá |

### Cài Đặt Geometry

```
\usepackage[
  a4paper,
  top=2.5cm, bottom=2.5cm,
  left=3cm, right=3cm
]{geometry}
```

## Common Patterns

### Code Listings

```
\usepackage{listings}
\begin{lstlisting}[language=Python]
def hello():
    print("Hello, World!")
\end{lstlisting}
```

### Toán Nhiều Dòng

```
\begin{gather}
  a + b = c \\
  d + e = f
\end{gather}

% Cases:
f(x) = \begin{cases}
  x^2 & x \geq 0 \\
  -x  & x < 0
\end{cases}
```
