LaTeX语法

文章目录

  • LaTeX
    • 环境准备
    • 基本结构
    • 文档类型和命令的使用
    • 内容层次
    • 文本内容和排版
      • 文字上色儿
      • 列表
      • 定义、定理和例子
      • 定义、定理和例子的编号
      • 缩进
      • 超链接
      • 表格
        • 基本格式
        • 单元格对齐
        • 行高
        • 格式调整
        • 合并单元格
        • 表格名称
        • 表格上色儿
      • 加载图像
      • 用户自定义命令
      • 重定义命令
    • 文档样式
      • 页面布局
      • 页眉和页脚
    • 数学环境
      • 排版
      • 希腊字母
      • 常用集合
      • 常用符号和运算符
      • 括号
      • 分段函数
      • 角度
      • 绝对值和范式
      • 求和、极限、导数、积分
      • 二项式系数
      • 矩阵和行列式
    • book类文档
      • 章节、小节标题
      • 书籍名称
      • 目录(toc)
      • 图像列表(lof)
      • 表格列表(lot)
      • 索引(index)
      • 参考文献
      • 附录
      • 包含其它文件
    • 输入中文

LaTeX

送柴侍御(唐 - 王昌龄)

沅水通波接武冈,送君不觉有离伤。
青山一道同云雨,明月何曾是两乡。

Latex中的命令格式: \CommandName[Optional Argument]{Compulsory Argument}

\CommandName{Compulsory Argument}[Optional Argument].

环境格式: \begin{environment}...\end{environment}.

环境准备

需要:

  • Tex Distribution
  • LaTex Editor

Tex Distribution:

  • TeX Live
  • MikTex

LaTeX Editor:

  • Texworks Editor
  • Texnic Center
  • Tex Studio

有用的网站: tex.stackexchange.com.

基本结构

\documentclass{article}
\begin{document}
\noindent Hello! \LaTeX{}\\ Latex is a typesetting system. \end{document}

文档类型和命令的使用

\documentclass{...}
% 这是注释
% \documentclass - 指出文档的类型
% \documentclass[options]{name of class}
% name of class 的选项是:
% article - 短的文章如报告、论文等
% report - 报告 exam - 考试或测验
% letter - 信件 book - 书籍
% beamer slides

% \documentclass 和 \begin{document} 之间的是 preamble
% preamble 是正文之前的配置

% \usepackage 的使用
% \usepackage[options]{name of package}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage{comment} % 多行注释

\begin{document}

% 下面是多行注释
\begin{comment}
A first line of comment.
A second line of comment.
\end{comment}

\end{document}
% 信件
\documentclass{letter}

\signature{Your name}
\address{From: \\Line 1 \\ Line 2 \\ Line 3}

\begin{document}

\begin{letter}{To:\\ Line 1 \\ Line 2 \\ Line 3}
\opening{Dear Sir\textbackslash Madam,}
This is content part.
\closing{Yours Faithfully,}
\ps{P.S. Here goes your ps.}
\encl{Enclosures.}
\end{letter}

\end{document}
% 研究类的文章
\documentclass[letterpaper]{article}

\usepackage{geometry,url,graphicx}
\title{A Sample Research Paper}
\author{X Y Z}
\date{dd-mm-yyyy}

\begin{document}

\maketitle
\abstract{An abstract}
\newpage
\tableofcontents
\newpage
\listoftables
\newpage
\section{Introduction}
An Introduction.
\section{Background and Preliminary}
A Background and Preliminary.
\section{First Main Section}
A first section.
\subsection{Subsection of I Section}
A subsection.
\subsection{Another Subsection of I Section}
Another subsection.
\section{Second Main Section}
A second section.
\subsection{Subsection of II Section}
A subsection.
\subsection{Another Subsection of II Section}
Another subsection.
\section{Conclusion}
A Conclusion
\newpage
\begin{thebibliography}{99}
\bibitem{Ref1} Author 1., \textit{Book 1}, Publisher 1, Year 1.
\bibitem{Ref2} Author 2., \textit{Book 2}, Publisher 2, Year 2.
\end{thebibliography}

\end{document}
\documentclass[letterpaper,11pt]{article}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage{amsmath}
\pagestyle{empty}
\begin{document}
    Math Quiz \hspace{1in} Name: \hrulefill
    \begin{enumerate}
        \item Suppose that $ax^2+bx+c=0$. Show that 
         \begin{displaymath}
             x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} ~.
         \end{displaymath}\vspace{0.75in}
        \item Solve the following system of equations:
         \begin{align*}
             2x - 4y ~&=~ \sum_{n=0}^1 \ln \left( e^3 \right)\\
             3x + 5y ~&=~ \int_0^1 2x\;dx ~+~ \lim_{x \to -\infty} \frac{\sin x}{\sqrt[3]{x}}
         \end{align*}\vspace{2in}
        \item Draw a right triangle $\triangle ABC$ with $C = 90^{\circ}$.\vspace{1in}
        \item Answer the following questions about the function $f(\theta) = \cos \theta$:
         \begin{enumerate}
             \item What is $f^\prime(\theta)$?\vspace{0.75in}
             \item What is $\lim_{\theta \to 0} f(\theta)$?
         \end{enumerate}
    \end{enumerate}
\end{document}
\documentclass[addpoints,12pt]{exam}
% \pointsinmargin
\pointsinrightmargin
\begin{document}

\begin{questions}
\question[10] I question
\question
\begin{parts}
    \part[5] I sub-section
    \part[5] II sub-section
    \part
    \begin{subparts}
        \subpart[3] I sub-question in (c)
        \subpart[2] II sub-question in (c)
    \end{subparts}
\end{parts}
\question[15] II question

\question[2] The correct option
\begin{choices}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{choices}

\question[2] The correct option \\
\begin{oneparchoices}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{oneparchoices}

\question[2] The correct option \\
\begin{checkboxes}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{checkboxes}

\end{questions}

\end{document}
\documentclass[addpoints]{exam}
\usepackage{amssymb}
\checkboxchar{\(\Box \)}
\pointsinrightmargin
\begin{document}

% \fillin: fill in the blank questions
% \begin{solution}...\end{solution}
% \printanswers \noprintanswers

\begin{questions}
    \question[2] The correct option
    \begin{checkboxes}
        \choice I Option
        \choice II Option
        \choice III Option
        \choice IV Option
    \end{checkboxes}

    \question[2] The correct option \\
    \begin{oneparchoices}
        \choice I Option
        \choice II Option
        \choice III Option
        \choice IV Option
    \end{oneparchoices}
\end{questions}

\end{document}

内容层次

Content Part Level
Part -1
Chapter 0
Section 1
Subsection 2
Subsection 3
Paragraph 4
Subparagraph 5

\part\chapter只对文档类型为bookreport的文档有用.

% 内容层次
\tableofcontents % 目录
\section{First section}
\section{Second section}
\subsection{A sub-section in II section}
\subsubsection[Deeper level]{A sub-section at deeper level}
\section{Third section}
\subsection{A subsection in III section}
\subsection{Another subsection in III section}

文本内容和排版

% \\ 换行 \newline 换行 \newpage 新的一页
% 通过空行或\par 开始新的段落
% 多个空格等价于一个空格 多个空白行等价于单行(空白折叠)
% '\'+' ' 等价于 一个空格

% 特殊字符
% 可使用\symbol{...}显示特殊字符, 要引入 \usepackage[T1]{fontenc}
% \ - \textbackslash
% %-\% $-\$ #-\# &-\& {-\{ }-\} _-\_
% {(left brace) - \symbol{123}
% }(right brace) - \symbol{125}
% _(underscore) - \symbol{95}
% ^(caret) - \symbol{94}
% ~(tilde) - \symbol{126}
% \copyright \textendash \textemdash \textregistered \texttrademark

% 字体
\texttt{Typewriter Font} % Monospaced
\textsf{Serif Font} % Sans serif
\textrm{Roman Font}

% 文本排版(Text formatting)

% 字体样式
% bold(粗体) - \textbf{...} italic(斜体) - \emph{...} or \textit
% bold italic - \textbf{\emph{...}} slanted - \textsl{Slanted text}
% underline(下划线) - \underline{...} small caps - \textsc{...}
% Superscript(上标) - \textsuperscript{...} (无需引入)
% subscript(下标) - \textsubscript (需要引入 fixltx2e 包)

% 字体大小
% script - \scriptsize{...}
% Footnote size - \footnotesize{...} tiny - \tiny{...}
% Small - \small{...} Normal size - \normalsize{...}
% Large - \large{...} Larger - \Large{...} Largest - \LARGE{...}
% Huge - \huge{...} Hugest - \Huge{...}
% Blue - \textcolor{blue}{...} 要加载xcolor包
% http://mirror.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf

% 定位
\begin{flushleft}
Flushed Left
\end{flushleft}
\begin{center}
Center Aligned
\end{center}
\begin{flushright}
Flushed Right
\end{flushright}

% 添加空白(水平和垂直) \hspace和\vspace
% \hspace{length} - length(正负皆可): in, cm, mm, pt
% \vspace{length}
% 1 inch = 72 pt
% \textwidth : 最大的length
A horizontal \hspace{10pt} space of 10 points.\\
A horizontal \hspace{2cm} space of 2 cm.\\

A first paragraph.

\vspace{1cm}
A second paragraph with additional space of 1cm.


% 水平线
% 格式: \rule[raise-height]{width}{thickness}
% raise-height: 水平线的高度,可选
% width: 水平线的长度,强制
% thickness: 水平线的粗细,强制
\rule{\linewidth}{1pt}
One inch line, 0.5 pts thick: \rule{1in}{0.5pt}\\
Same as above, 3 pts lower:\\
\rule[-3pt]{1in}{0.5pt}\\
Line to right margin: \hrulefill \\
Put a line across the page:\\
\hrule

文字上色儿

\documentclass{article}
\usepackage{color} % 引入
% 使用 color 包用 \pagecolor{color} 命令设置页面背景色
\begin{document}
% 命令格式: \color{declared-color}{text}
\color{red}{Red}
\color{green}{Green}
\end{document}

列表

% 有序列表(块级)
\begin{enumerate}
    \item This is item 1.
    \item This is item 2.
        \begin{enumerate}
            \item This is item 2.1.
            \item This is item 2.2.
        \end{enumerate}
    \item This is item 3.
\end{enumerate}

% 无序列表(块级)
\begin{itemize}
    \item This is the first bullet item.
    \item This is the second bullet item.
    \item This is bullet item 3.
\end{itemize}
% 块级
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=\alph*.]
% \begin{enumerate}[label=\Alph*)]
% \begin{enumerate}[label=\roman*.]
% \begin{enumerate}[label=\Roman*.,start=3]
% [label={}]作用与无标识的列表
\item First
\item Second
\item Third
\end{enumerate}
\end{document}
\documentclass{article}
\usepackage{paralist} % 行内列表
\begin{document}
\begin{inparaenum}
% \begin{inparaenum}[a)]
\item First
\item Second
\item Third
\end{inparaenum}
\end{document}

定义、定理和例子

% 块级
% f\/i 用于正确调整f和i之间的空白
\begin{description}
\item[I Def\/inition:]I def\/inition
\item[II Def\/inition:]II def\/inition
\item[III Def\/inition:]III def\/inition
\end{description}
% 行级
\documentclass{article}
\usepackage{paralist}
\begin{document}
\begin{inparadesc}
\item[I Def\/inition:]I def\/inition
\item[II Def\/inition:]II def\/inition
\item[III Def\/inition:]III def\/inition
\end{inparadesc}
\end{document}

定义、定理和例子的编号

命令格式:\newtheorem{nickname of environment}{name of environment as to be printed}[within].

\newtheorem{nickname of environment}[numbered like]{name of environment as to be printed}.

within(定理前的序号如章节、小节等的编号如Theorem 2.1.1): \newtheorem{thmv}{Theorem}[section].

numbered like: 已经定义的环境的名称.

\newtheorem{thmv}{Theorem}
\newtheorem{dfnb}[thmv]{Definition}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newtheorem{thmv}{Theorem}
\newtheorem{dfnb}{Definition}
\newtheorem{lem}{Lemma}
\begin{thmv}
This is a theorem.
\end{thmv}
\begin{thmv}
This is another theorem.
\end{thmv}
\begin{dfnb}
This is definition.
\end{dfnb}
\begin{dfnb}
This is another definition.
\end{dfnb}
\begin{lem}
This is lemma.
\end{lem}
\end{document}

缩进

\documentclass{article}
\begin{document}
\begin{tabbing}
% \= 设置 tab positions
% \> 移动到 tab positions
\= Tab1 \= Tab2 \= Tab3 \= Tab4\\
\> Tab1 \\
\> \> Tab2 \\
\> \> \> Tab3 \\
\> \> \> \> Tab4
\end{tabbing}
\end{document}

超链接

\documentclass[a4paper,12pt]{article}
\usepackage[colorlinks=true]{hyperref}
\usepackage{url,hyperref}
\usepackage{bookmark}
\begin{document}
\section{First Section}
\href{www.latex.com}{some text}
\section{Second Section}
\url{www.latex.com}
\subsection{A subsection}
\nolinkurl{www.latex.com}
\end{document}

表格

环境: \begin{tabular}...\end{tabular}.

可使用包array和包booktabs调整表格样式.

基本格式

\textbf{Center Aligned}\\

\begin{tabular}{|c|c|c|} % l(左对齐) c(居中) r(右对齐)
\hline
Col. 1 & Col. 2 & Col. 3\\
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}\\

\textbf{Fixed Width}\\

\begin{tabular}{|p{1.5cm}|p{2cm}|p{1.5cm}|}
% 少用竖线以提高表格内容的可读性
\hline
Col. 1 & Col. 2 & Col. 3\\
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}\\

单元格对齐

\documentclass{article}
\usepackage{array}
\begin{document}

\textbf{Cell Alignment:}\\

\begin{tabular}{|b{1.6cm}|m{1.6cm}|p{1.6cm}|}
\hline
top aligned & middle aligned & bottom aligned\\
\hline
\end{tabular}

\end{document}

行高

\documentclass{article}
\usepackage{array}
\begin{document}

\setlength{\extrarowheight}{16pt}
\begin{tabular}{|c|c|c|}
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
\end{tabular}

\end{document}

格式调整

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{ccc}
\toprule[1.5pt]
A & B & C \\
\midrule
11 & 12 & 13 \\
21 & 22 & 23 \\
31 & 32 & 33 \\
\bottomrule[1.5pt]
\end{tabular}

\end{document}

合并单元格

\documentclass{article}
\begin{document}

% \multicolumn{cols}{pos}{text}
% cols: specifies the number of columns to span
% pos: specifies the formatting of the entry; c(centered),l(left),r(right)
% text: specifies what text is to make up the entry
\begin{tabular}{ccc}
\hline
\multicolumn{2}{l}{Combined Column} &
\multicolumn{1}{l}{Last Column}\\
\cline{1-2}
11 & 12 & 13 \\
21 & 22 & 23 \\
31 & 32 & 33 \\
\hline
\end{tabular}

\end{document}
\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{ccc}
\toprule[1.5pt]
\multicolumn{2}{l}{Combined Column}&
\multicolumn{1}{l}{Last Column}\\
A & B & C\\
\cmidrule(r){1-2}\cmidrule(l){3-3}
11 & 12 & 13 \\
21 & 22 & 23 \\
31 & 32 & 33 \\
\bottomrule[1.5pt]
\end{tabular}
    
\end{document}

表格名称

\begin{table}[htbp]
\begin{tabular}{ccc}
\hline
Col. 1 & Col. 2 & Col. 3 \\
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}
\centering
\caption{Table Name - Below} % 这是表格标题
\end{table}

\begin{table}[htbp]
\centering
\caption{Table Name - Above} % 这是表格标题
\vspace{10pt}
\begin{tabular}{ccc}
\hline
Col. 1 & Col. 2 & Col. 3 \\
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}\\
\end{table}

表格上色儿

% 设置一行的颜色
\documentclass{article}
\usepackage{colortbl}
\begin{document}

\begin{tabular}{ccc}
\hline
\rowcolor{red}
11 & 12 & 13 \\
\hline
\rowcolor{blue}
21 & 22 & 23 \\
\hline
\rowcolor{green}
31 & 32 & 33 \\
\hline
\end{tabular}

\end{document}
% 设置一列的颜色
\documentclass{article}
\usepackage{colortbl}
\begin{document}

\begin{tabular}
{>{\columncolor{red}}c>
{\color{white}\columncolor{blue}}c>
{\color{yellow}\columncolor{green}}c}
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}

\end{document}

加载图像

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\begin{figure}[htbp]
\begin{center}
% \includegraphics[width=0.3\width, angle=0]{sample.jpg}
% 占页面的 30%
% \includegraphics[scale=0.85]{sample.jpg}
\fbox{\includegraphics[width=3cm, angle=0]{sample.jpg}}
\caption{Sample Figure}
\end{center}
\end{figure}

I'm going to box \fbox{this text} first.
\fbox{\parbox{\textwidth}{This whole
paragraph will be boxed. This will make it
seem as if it is very important.}}

\end{document}

用户自定义命令

\documentclass{article}
\begin{document}

\newcommand{\xyz}{This is user defined command.}
\xyz

\newcommand{\poly}{a_0+a_1x+\cdots+a_nx^n}
\[\poly\]

\newcommand{\polyd}[1]{a_0+a_1x+\cdots+a_#1x^#1}
\[\polyd{m}\]
\[\polyd{n}\]

\newcommand{\polyv}[2]{a_0+a_1#1+\cdots+a_#2#1^#2}
\[\polyv{x}{m}\]
\[\polyv{y}{n}\]

% \newcommand{command name}[number of arguments]{definition}
% number of arguments: 参数个数 - 1 到 9
% #n: 代表第 n 个参数

\end{document}

重定义命令

\renewcommand{\textbf}{\textit}
\textbf{Italic text with redefined \textbackslash textbf!}

\newcommand{\xyz}{This is user defined command.}
\xyz
\renewcommand{\xyz}[2]{A redefined xyz command of args. #1 and #2.}
\xyz{a}{b}
\documentclass{article}
\begin{document}


\end{document}

文档样式

页面布局

\documentclass{artilce}
\begin{document}
% 页面默认布局:
% Paper Size: Letter
% Font: Computer Modern
% Font Size: 10pt
% Orientation: Portrait, One Column
Hello, world!
\end{document}
\documentclass[14pt,twocolumn]{artilce}
\usepackage[a4paper,landscape]{geometry}
\begin{document}
% 页面布局:
% Paper Size: A4
% Font: Computer Modern
% Font Size: 14pt
% Orientation: Landscape, Two Columns
Hello, world!
\end{document}

页面大小: a0paper,a1paper,...,a6paper,b0paper,b1paper,...,b6paper,letterpaper,legalpaper等.

页眉和页脚

% 统一设置页眉和页脚的样式
\documentclass{article}
\usepackage{fancyhdr} % 引入
\pagestyle{fancy} % \pagestyle{empty} 不标记页码
\renewcommand{\headrulewidth}{0pt} % 删除header后的水平线
\lhead{LH}
\chead{CH}
\rhead{RH}
\lfoot{LF}
\cfoot{Page \thepage} % 设置页码
\rfoot{RF}
\begin{document}
This is content part.
\end{document}
% 设置不同页面的页眉和页脚的不同样式
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\lhead{LH}
\chead{CH}
\rhead{RH}
\lfoot{LF}
\cfoot{Page \thepage}
\rfoot{RF}
\begin{document}
First page.
\newpage
\thispagestyle{empty}
Second page.
\newpage
Third page.
\end{document}
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\lhead{lh}
\chead{ch}
\rhead{rh}
\lfoot{lf}
\cfoot{Page \thepage}
\rfoot{rf}
\fancypagestyle{mystyle}
{\fancyhf{} % 重新设置页眉和页脚
\fancyhead[l]{Lh}
\fancyhead[c]{Ch}
\fancyhead[r]{Rh}
\fancyfoot[l]{Lf}
\fancyfoot[c]{Cf}
\fancyfoot[r]{Rf}
}
\begin{document}
First page.
\newpage
\thispagestyle{mystyle} % 应用样式
Second page.
\newpage
Third page.
\end{document}

数学环境

行级数学环境: \(...\)$...$.

块级数学环境: \[...\]$$...$$.(少用$),\begin{displaymath}...\end{displaymath}.

% http://ctan.org/tex-archive/info/symbols/comprehensive/symbols-letter.pdf
% https://mirror.bjtu.edu.cn/CTAN/info/
Fraction: $\frac{dy}{dx} = \dfrac{dy}{dx}$\\
Sum: $\sum_{n=1}^{\infty} = \displaystyle\sum_{n=1}^{\infty}$\\
Limit: $\lim_{n \to \infty} = \displaystyle\lim_{n \to \infty}$\\
Integral: $\int_a^b = \displaystyle\int_a^b$

编号的数学环境: \begin{equation}...\end{equation}.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
    f(x) &= e^{x-1}\\
    \int_1^2 f(x)\;dx &= e^{x-1} ~\Bigr|_1^2\\
    &= e - 1
\end{align*}

\begin{align}
    2x-4y-7z+82 &= \pi\\
    3x+5y+9z &= 213\\
\end{align}
\end{document}

排版

% multline 环境
\documentclass{article}
\usepackage[fleqn]{amsmath}
\begin{document}
\begin{multline}
x = a + b + c + d + e +\\
f + g + h + j +\\
k + l + m + n
\end{multline}

% 使用~或\text{some text}展开空白
Bad: sin x is a function\\
Terrible: $sin x is a function$\\
Good: $\sin x ~\text{is a function}$\\
Good: $\sin x$ is a function\\
\end{document}
% align 环境
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
x + y + z = 1\\
y + z = 0\\
u + v + w + z = 2
\end{align}
\end{document}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
  \begin{split}
    a = b\\
    =c\\
  \end{split}
\end{equation}
\end{document}

无编号的数学环境: \begin{equation*},\begin{multline*},\begin{gather*},\begin{align*}.

部分无编号: \nonumber.

\[x,y,z\]\\
\[x_1\]\\ % subscript
\[x^2\]\\ % exponent
\[x_1^2\]\\
\[\sqrt{x}\]\\
\[\sqrt[3]{x}\]\\
\[\sqrt{\sqrt{x}}\]\\
\[\sqrt[n]{y_2^3}\]\\
\[\frac{x}{y}\] % fraction

希腊字母

% \alpha \beta \gamma \Gamma \delta \Delta
% \epsilon \zeta \eta \theta \kappa \lambda
% \mu \pi \rho \sigma \Sigma \tau \phi \Phi
% \chi \psi \omega \Omega \nabla \xi

常用集合

\documentclass{article}
\usepackage{bbm}
\begin{document}
\[\mathbbm{C,Z}\]\\
\[\mathbbm{Q,R}\]\\
\[\mathbbm{N,Z_+}\]\\
\[\mathbbm{R^+,R^-}\]\\
\[\mathbbm{P,T}\]\\
\end{document}

常用符号和运算符

% multiplication(乘法) - \times
% division(除法) - \div
% plus or minus(正负号) - \pm
% 无穷 - \infty
% 大于等于 - \geq 小于等于 - \leq
% 不等于 - \neq
% 远小于 - \ll 远大于 - \gg
% \prec \preceq \succ \succeq
% 任意 - \forall 存在 - \exists
% 不存在 - \not\exists 当且仅当 - \iff
% similar(相似) - \sim \cong \simeq
% approximately(约等于) - \approx
% equivalent(等价) - \equiv 不垂直 - \not\perp
% perpendicular(垂直) - \perp parallel(平行) - \parallel
% 成正比 - \propto 与 - \wedge 或 - \vee
% \bigwedge \bigvee \mid \ast(asterisk, 星号)
% degrees(度数) - 45^{\circ} angle(角) - \angle A
% triangle(三角形) - \triangle ABC \triangleleft \triangleright \bigtriangleup
% \bigtriangledown \circ \bigcirc
% square(正方形) - \square
% 属于 - \in \ni 差集 - \setminus
% intersection(交集) - \cap union(并集) - \cup
% subset(子集) - \subset \supset empty set(空集) - \emptyset
% \subseteq \supseteq \bigcup \bigcap \sqcup \sqcap \bigsqcup
% \oplus \ominus \oslash \odot \otimes
% \bigoplus \bigotimes \bigodot
% implies - P \Rightarrow Q
% Two-way implication - P \Leftrightarrow Q
% \sin x \cos x \tan x \csc x \sec x
% \cot x \arcsin x \arccos x \arctan x
% \sinh x \cosh x \tanh x \log x \ln x
% \log_b x \exp \max \min \inf \sup
% a \equiv r(\bmod\; n)
% \dot{x} \ddot{x} \bar{x} \tilde{x} \hat{x}
% \vec{v} \cdot vec{w} \overline{AB} \overrightarrow{AB}
% \check{a} \acute{a} \breve{a}
% \cdots \ldots \underline{AB} \widetilde{abc} \widehat{abc}
% \overbrace{abc} \underbrace{abc}
\documentclass{article}
\usepackage{amsmath} % 需要引入
\usepackage{amssymb}
\begin{document}
% 因为 - \because 所以 - \therefore
% 蕴涵 - \implies
% \nless \ngtr \nleq \ngeq
% \nsubseteq \nsupseteq \subsetneq \supsetneq
% \nmid \nparallel \nsim \ncong
% \centernot\implies
% \centernot\iff
% \centernot\mid
% \centernot\perp
% \centernot\equiv
% \centernot\parallel
% \centernot\sim
% \centernot\cong
\end{document}

括号

\[ \Biggl( \biggl( \Bigl( \bigl( ( \]
\[ ) \bigr) \Bigr) \biggr) \Biggr) \]
\[ \Biggl[ \biggl[ \Bigl[ \bigl[ [ \]
\[ ] \bigr] \Bigr] \biggr] \Biggr] \]
\[ \Biggl| \biggl| \Bigl| \bigl| | \]
\[ | \bigr| \Bigr| \biggr| \Biggr| \]

\begin{displaymath}
    \left( \frac{1}{2} \right) ,~
    \left\lbrace e^{x^2 + y^2} \right\rbrace ,~
    \left\lbrack \iint f~dS  \right\rbrack ,~
    \left| \frac{\partial f}{\partial x} \right|
\end{displaymath}

分段函数

\documentclass{article}
\usepackage{bbm}
\begin{document}
\( f: \mathbbm{R} \setminus \{0\} \to \mathbbm{R}\)
defined as \\
\(f(x) = \frac{\sin{x}}{x} \)
\( f: \mathbbm{R} \to \mathbbm{R} \)
defined as\\
\(f(x) = 
\left\{
\begin{array}{ll}
  x & \mbox{if } x \geq 0 \\
  -x & \mbox{if } x < 0
\end{array}
\right. \)
\end{document}

角度

\documentclass{article}
\usepackage{gensymb}
\begin{document}
\[90\degree\]
\end{document}

绝对值和范式

\documentclass{article}
\usepackage{commath}
\begin{document}
\[\abs{x}\]
\[\norm{x}\]
\[\norm{\frac{x}{\abs{y}}}\]
\end{document}

求和、极限、导数、积分

% summation(求和) - \sum_{n=1}^{N}a_n or \sum\limits_{n=1}^{N}a_n
% limit(极限) - \lim_{x \to \infty} f(x) or \lim\limits_{x \to \infty} f(x)
% derivative(导数) - f^\prime(x)
% \frac{dy}{dx} \frac{d^2y}{dx^2} \frac{\partial z}{\partial x}
% \frac{\partial^2 z}{\partial z^2}
% \frac{\partial^2 z}{\partial x \partial y}
% indefinite integral - \int f(x)\,dx and \int \!f(x)\,dx
% \! 用于减少积分号和被积函数之间的空白
% definite integral - \int_{a}^{b}f(x)\,dx
% \int_{0}^{2}\!x\,\mathrm{d}x
% \mathrm用于格式化
% double integral(双重积分) - \iint\limits_R f\,dA
% triple integral - \iiint\limits_S f\,dV
% multiple integral(多重积分) - \idotsint\limits_V
% line integral - \oint_C f\,ds

二项式系数

Binomial Coefficients

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\binom{n}{r}\]
\[^nC_r\]
\[^nP_r\]
\end{document}

矩阵和行列式

\( A = \begin{array}{cc}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{array} \)

\( A = \left(
\begin{array}{cc}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{array} 
\right) \)

\( A = \left[
\begin{array}{cc}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{array} 
\right] \)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{displaymath}
    A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix},~
    B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix},~
    |A| = \begin{vmatrix} 1 & 2 \\ 3 & 4 \end{vmatrix}
\end{displaymath}

\( A = \begin{matrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{matrix} \)

\( A = \begin{pmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{pmatrix} \)

\( A = \begin{bmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{bmatrix} \)

\( A = \begin{vmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{vmatrix} \)

\( A = \begin{Vmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{Vmatrix} \)

\( A = \begin{Bmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}
\end{Bmatrix} \)
\end{document}

book类文档

章节、小节标题

\documentclass{book}
\begin{document}
% Part -> Chapter -> Section -> Sub-section -> Sub-section at Deeper Level
\part{First Part}
\chapter*{Preface} % *: 章节不计入数字
\chapter{First main chapter}
\section{A section}
\section{Another section}
\subsection{A sub-section}
\subsubsection[Deeper level]{A sub-section at deeper level}
\chapter{Second main chapter}
\part{Second part}
\chapter{Third main chapter}
\chapter{Fourth main chapter}
\end{document}

书籍名称

\documentclass{book}
\begin{document}

\begin{titlepage}
\noindent{\Huge Name of Book \\ \\ }
{\large edition \\ \\ \\ }
{\Large Author \\ }
\vfill
{\itshape year, Publisher}
\end{titlepage}

\end{document}

目录(toc)

\documentclass{book}
\usepackage[colorlinks=true, linkcolor=black]{hyperref}
\setcounter{tocdepth}{1}
% \setcounter{tocdepth}{depth level}
% Part -1 Chapter 0 Section 1
% Subsection 2 subsubsection 3
% Paragraph 4 Subparagraph 5
\begin{document}

\tableofcontents % 这是目录

% \addcontentsline: 向目录中添加内容
% \addcontentsline{toc}{level}{Name of Entry}
% level: part, chapter, section, subsection

\part{First Part}
\chapter*{Preface}

\addcontentsline{toc}{chapter}{Preface}

\chapter{First main chapter}
\section{A section}
\section{Another section}
\subsection{A sub-section}
\subsubsection[Deeper level]{A sub-section at deeper level}
\chapter{Second main chapter}
\part{Second part}
\chapter{Third main chapter}
\chapter{Fourth main chapter}

% \addtocontents{toc}{Name of Entry}: 向目录中添加内容(不显示页码)

\addtocontents{toc}{Some Description of Section}

\section{A section in IV Chapter}
\end{document}

图像列表(lof)

\documentclass{book}
\usepackage{graphicx}
\begin{document}
    \listoffigures
    \part{First Part}
    \chapter*{Preface}
    \chapter{First main chapter}
    \section{A section}
    \addtocontents{lof}{some description before figure}
    \begin{figure}[htbp]
        \begin{center}
            \fbox{\includegraphics[width=4cm,angle=0]{sample.jpg}}
            \caption{Sample Figure}
        \end{center}
    \end{figure}
    \addcontentsline{lof}{figure}{some description after figure}
    \section{Another section}
    \subsection{A smaller section}
    \subsubsection[Deeper level]{This section has an even deeper level}
    \chapter{Second main chapter}
    \part{Second part}
    \chapter{Third main chapter}
\end{document}

表格列表(lot)

\documentclass{book}
\begin{document}
    \listoftables
    \part{First Part}
    \chapter*{Preface}
    \chapter{First main chapter}
    \section{A section}
    \addtocontents{lot}{some description before table}
    \begin{table}[htbp]
        \begin{tabular}{ccc}
            \hline
            \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\
            \hline
            11 & 12 & 13 \\
            21 & 22 & 23 \\
            31 & 32 & 33 \\
            \hline
        \end{tabular}
        \centering
        \caption{Table Name}
    \end{table}
    \addcontentsline{lot}{table}{some description after table}
    \section{Another section}
    \subsection{A smaller section}
    \subsubsection[Deeper level]{This section has an even deeper level}
    \chapter{Second main chapter}
    \part{Second part}
    \chapter{Third main chapter}
\end{document}

索引(index)

\documentclass{book}
\usepackage{index,graphicx}
\makeindex
\begin{document}
    % \index{Index Entry}
    % \index{Index Entry|see{other Index Entry}}
    \part{First Part}
    \chapter*{Preface}
    \chapter{First main chapter}
    \section{A section}
    \index{index entry A}
    \section{Another section}
    \subsection{A smaller section}
    \subsubsection[Deeper level]{This section has an even deeper level}
    \chapter{Second main chapter}
    \part{Second part}
    \index{index entry B}
    \begin{figure}[htbp]
        \begin{center}
            \fbox{\includegraphics[width=4cm,angle=0]{sample.jpg}}
            \caption{\index{some figures}Sample Figure}
        \end{center}
    \end{figure}
    \chapter{Third main chapter}
    \index{index entry C}
    \index{index entry A}
    \index{index entry D |see{index entry C}}
    \printindex
\end{document}

参考文献

\documentclass{book}
\begin{document}
    \part{First Part}
    \chapter*{Preface}
    \chapter{First main chapter}
    \section{A section}
    \section{Another section}
    \subsection{A smaller section}
    You may refer to \cite{Ref1} and also to \cite{Ref2}.
    \subsubsection[Deeper level]{This section has an even deeper level}
    \chapter{Second main chapter}
    \part{Second part}
    \chapter{Third main chapter}
    \begin{thebibliography}{99}
        % \bibitem[label]{cite_key}
        \bibitem[Label 1]{Ref1} Author 1., \textit{Book 1}, Publisher 1, Year 1.
        \bibitem[Label 2]{Ref2} Author 2., \textit{Book 2}, Publisher 2, Year 2.
    \end{thebibliography}
\end{document}

附录

\documentclass{book}
\begin{document}
    \tableofcontents
    \part{First Part}
    \chapter*{Preface}
    \addcontentsline{toc}{chapter}{Preface}
    \chapter{First main chapter}
    \section{A section}
    \section{Another section}
    \subsection{A smaller section}
    \subsubsection[Deeper level]{This section has an even deeper level}
    \chapter{Second main chapter}
    \part{Second part}
    \chapter{Third main chapter}
    \appendix
    \cleardoublepage % \clearpage
    \addtocontents{toc}{\bigskip}
    \addcontentsline{toc}{part}{Appendix}
    \chapter{Glossary} % 这是附录的组成部分
    \chapter{Symbols} % 这也是附录的组成部分
\end{document}

包含其它文件

\input{filename}include{filename}.

输入中文

\documentclass{article}
\usepackage[UTF8]{ctex}
\begin{document}
    这是内容。
\end{document}

[languages - How does one type Chinese in LaTeX? - TeX - LaTeX Stack Exchange](https://tex.stackexchange.com/questions/17611/how-does-one-type-chinese-in-latex?r=SearchResults).

你可能感兴趣的:(latex)