在word里的公式打到头秃,遂转向Latex,现在网上的大部分语法和符号整理似乎都不是非常全面,每次需要打开多个网页寻找。因此记录Latex使用过程中的一些常见语法结构及常用的数学符号,便于查阅~ ('>A<')
本文配置环境为MacTex+Texpad,结果示例以截图形式表示。
一、语法结构
1. 文件组织
一个latex的文件语言大概是一堆看上去是酱紫的代码:
%导言区
\documentclass[a4paper,12pt]{article}
% documentclass中article 文档适合较短的文章,比如期刊文章和短篇报告。其他文档类型包括
% report(适用于更长的多章节的文档),proc(会议论文集),book 和 beamer。也可设置纸张
% 大小和主要文字大小。
%\usepackage[UTF8]{ctex} 中文加上这一行
%文件部分
\begin{document}
...
\end{document}
2. 主题
\title{Lucky day}
\author{Khan}
%\date{\today} %如果你想使用今天的时间
\date{2022年12月12日}
\maketitle
3. 章节
\chapter{...} %report 和 book
\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}
4. 目录
在章节的基础上可以使用以下代码生成
\pagenumbering{roman}
\tableofcontents
\newpage
\pagenumbering{arabic}
5.字体
一些常用的字体:
%代码最前端加入包 \usepackage{color}
\textit{words in italics} %斜体
\textsl{words slanted} %斜体
\textsc{words in smallcaps} %小写单词
\textbf{words in bold} %黑体
\texttt{words in teletype} %电传字
\textsf{sans serif words} %无衬线词
\textrm{roman words} %罗马字
常用字体效果:
text
\underline{underlined words} %下划线
\textit{text} %斜体
\textbf{text} %粗体
\pagecolor{yellow} %设置页面颜色;
\colorbox{red}{red words} %文字底纹颜色
\textcolor{blue}{blue words} %有色文字
\fcolorbox{outline color}{box color}{text} %带边框的盒子颜色及框颜色
%一些不常用的:
\sout{text} %删除线,需要宏包 \usepackage{ulem}
\textcolor{color!percentage}{text} %半色调,宏包 \usepackage[cmyk]{xcolor}
\textcolor{color!percentage!color}{text} %混合色 宏包同上
\textcolor{-color}{text} %互补色 宏包同上
常用的字体大小调整:
normal size words
{\tiny tiny words}
{\scriptsize scriptsize words}
{\footnotesize footnotesize words}
{\small small words}
{\large large words}
{\Large Large words}
{\LARGE LARGE words}
{\huge huge words}
6. 换行与缩进
%缩进
\noindent %消除首行缩进两字符
\setlength{\parindent}{2em} %首行全部缩进两字节,影响其后的所有段落
%换行
\\ %换行不缩进
\par %换行+缩进两字符
%直接空一行 换行+缩进两字符
\\ \hspace*{\fill} \\ %使两行之间空出一行的距离
7. 列表
\begin{enumerate}
\item First thing
\item Second thing
\begin{itemize}
\item A sub-thing
\item Another sub-thing
\end{itemize}
\item Third thing
\end{enumerate}
%可以用 \item[-] 来修改标志
8. 表格
\begin{tabular}{...}中省略号的参数会由定义表格的列的代码替换:
l
表示一个左对齐的列;r
表示一个右对齐的列;c
表示一个向中对齐的列;|
表示一个列的竖线;
例如,{lll}
会生成一个三列的表格,并且保存向左对齐,没有显式的竖线;{|l|l|r|}
会生成一个三列表格,前两列左对齐,最后一列右对齐,并且相邻两列之间有显式的竖线。
表格的数据在 \begin{tabular}
后输入:
&
用于分割列;\\
用于换行;\hline
表示插入一个贯穿所有列的横着的分割线;\cline{1-2}
会在第一列和第二列插入一个横着的分割线。
\begin{tabular}{lll}
\hline
序号 & 符号 & 定义\\
\hline
1 & a & 参数1\\
2 & b & 参数2\\
3 & c & 参数3\\
4 & d & 参数4\\
\hline
\end{tabular}
添加表头
\begin{table}[H] %H让插入的表紧跟在文字后面
\centering
\caption{符号说明}
\begin{tabular}{@{}ccc@{}}
\hline
\textbf{符号} & \textbf{说明} & \textbf{单位} \\
\hline
$a_l$ & 参数1 & ms \\
$a_2$ & 参数2 & $mg/mm^{3}$ \\
$a_3$ & 参数3 & $mg/mm^{3}$ \\
$a_4$ & 参数4 & $mg/mm^{3}$ \\
\hline
\end{tabular}
\end{table}
9. 图片
[h]
是位置参数,h 表示把图表近似地放置在这里(如果能放得下)。有其他的选项:t 表示放在在页面顶端;b 表示放在在页面的底端;p 表示另起一页放置图表。
[width=1\textwidth]
是一个可选的参数,它指定图片的宽度——与文本的宽度相同。宽度也可以以厘米为单位。你也可以使用 [scale=0.5]
将图片按比例缩小(示例相当于缩小一半)。
%宏包 \usepackage{graphicx}
\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{myimage}
\caption{Here is my image}
\label{image-myimage}
\end{figure}
子图处理:
%宏包 \usepackage{float} %设置图片浮动位置的宏包
%宏包 \usepackage{subfigure} %插入多图时用子图显示的宏包
\begin{figure}[!htbp]
\centering
\subfigure[fig1]{\includegraphics[width=0.45\textwidth]{love.jpeg}}
\quad
\subfigure[fig2]{\includegraphics[width=0.45\textwidth]{love.jpeg}}
\subfigure[fig3]{\includegraphics[width=0.45\textwidth]{love.jpeg}}
\caption{子图排列}
\end{figure}
10. 公式
行内公式
$a+b=c$
行间公式
$$a+b=c$$
带标号公式
\begin{equation}
a+b=c
\end{equation}
其他:
^ %上标
_ %下标
\frac{numerator}{denominato} %分数
$$\sqrt[x]{y^2}$$ %根号
$$\sum_{x=1}^5 y^z$$ %求和
$$\int_a^b f(x)$$ %积分
11. 引用
标签:
\label{labelname} %创建标签
\ref{labelname} %引用
参考文献
\bibliographystyle{plain}
\bibliography{references}
引用列表写在references.bib里
@article{
Birdetal2001,
Author = {Bird, R. B. and Smith, E. A. and Bird, D. W.},
Title = {The hunting handicap: costly signaling in human foraging strategies},
Journal = {Behavioral Ecology and Sociobiology},
Volume = {50},
Pages = {9-19},
Year = {2001}
}
Field name = {field contents},
引用文献:
\cite{citationkey}
\cite[p. 215]{citationkay} %带页码
\cite{citation01,citation02,citation03} %多个文献
二、常用符号
特殊字符# $ % ^ & _ { } ~ \ 要加反斜杠转义,反斜杠使用 \textbackslash 转义
\circ
不太常用的:
\xleftarrow[a+c]{\text{maps to}}
持续更新中~
参考:
[2]latex常用语法笔记_latex空心1_Zkangda的博客-CSDN博客
[3]https://www.cnblogs.com/hushunlin/p/15140731.html
[4]latex 用法查询大全(不断补充中~~)_latex \in_大黑山修道的博客-CSDN博客
[6]LaTex常用的一些语法【超实用-新手入门】_\cref_brilliant・ω・ ~つと)的博客-CSDN博客
[7]Manuscript Preparation in LATEX . 2017. Wiley Authoring Template
[9]LaTex - 缩进、换行和换段_latex缩进_不想当厨师的程序员不是一个好画家的博客-CSDN博客