给最近自己学习Latex的各种命令做个笔记,方便后续编辑,不定期更新
一、环境配置相关
1.如何使用中文(以VsCode中为例)
首先需要配置setting.json(可在插件-扩展文件中打开),将内容跟换为以下内容,即需要xelatex作为编译器。
{
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
],
},
{
"name": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.autoBuild.run": "onFileChange",
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
}
而后在Tex文件中调用即可使用中文:
\usepackage[UTF8]{ctex}
二、文章内容相关
模板
\documentclass{article}
% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[UTF8]{ctex}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\title{CDC-0911}
\author{Zhou}
\begin{document}
\maketitle
\section{Matlab Function的部署}
\end{document}
1.封面格式
在\begin{document}前需要定义
\title{some words}
\author{You}
\date{\today}
而后在{document}中
\maketitle
2.章节内容
\section{Some examples to get started}
\subsection{How to create Sections and Subsections}
3.插入图片
需要实现导入包
\usepackage{graphicx}
后续document中即可通过以下实现图片插入
\begin{figure}[htbp]
\centering
\includegraphics[height=4.5cm,width=9.5cm]{image/Abstract_Submission.png}
\caption{}
\end{figure}
可以通过命令使得图片放缩
\includegraphics[scale=0.8]{image/coordinate.png}
三、公式编辑相关
1.段落内直接添加公式
需要通过(...中写入符合Latex语法格式表示的数学表达式,如字母、公式等)
$ ... $
举例如下
\LaTeX{} is great at typesetting mathematics. Let $X_1, X_2, \ldots, X_n$ be a sequence of independent and identically distributed random variables with $\text{E}[X_i] = \mu$ and $\text{Var}[X_i] = \sigma^2 < \infty$, and let
\[S_n = \frac{X_1 + X_2 + \cdots + X_n}{n}
= \frac{1}{n}\sum_{i}^{n} X_i\]
denote their mean. Then as $n$ approaches infinity, the random variables $\sqrt{n}(S_n - \mu)$ converge in distribution to a normal $\mathcal{N}(0, \sigma^2)$.
2.独立公式
需要通过begin,另起一个新环境,表现效果为换行居中显示公式
\begin{equation}
E=mc^2
\end{equation}
存在大括号括起多行公式的情况
\begin{equation}
\begin{cases}
\dot{X} = \dot{x} \cdot cos(\varphi)-\dot{y} \cdot sin(\varphi ) \\
\dot{Y} = \dot{x} \cdot sin(\varphi)+\dot{y} \cdot cos(\varphi )
\end{cases}
\end{equation}
给公式打上标签后,后续即可通过\ref命令引用(但注意\ref需要连续编译两次才可以正确显示,不然就会显示??)
\begin{equation}
\begin{cases}
\dot{s\_t\_x} = \dot{v\_t\_x} \cdot cos(\varphi)-\dot{v\_t\_y} \cdot sin(\varphi ) \\
\dot{s\_t\_y} = \dot{v\_t\_x} \cdot sin(\varphi)+\dot{v\_t\_y} \cdot cos(\varphi )
\label{equation2}
\end{cases}
\end{equation}
3.表格
表格具有多种实现方式
\begin{enumerate}
\item Like this,
\item and like this.
\end{enumerate}
\dots or bullet points \dots
\begin{itemize}
\item Like this,
\item and like this.
\end{itemize}
四、报错
4.1 IEEE Latex模板编译报错
Font shape `TU/ptm/b/n' undefined
(Font) using `TU/ptm/bx/n' instead.
LaTeX
解决方案:选择pdflatex编译器进行编译即可。