常用 LaTeX 语法总结
本文总结自己验证过的 LaTeX 语法,逐渐积累更新,使用方式:Ctrl+F 搜索关键字,直接拿过来用
去哪里找 LaTeX 模板或者代码?
- Overleaf 的教程找伪代码,图片之类的代码模版
- Overleaf template 找 poster,cv 等 各种优质模板
- LaTeXStudio
画图
Latex 中插入多张图片,实现并排排列或者多行多列排列_泽米的博客-CSDN 博客_tex 多张图并列画图
调整图片大小
1 | \includegraphics[width=15cm, height=6cm, keepaspectratio]{name1} |
1 | (\includegraphics[width=\textwidth, height=\textheight]{figure.pdf}) |
Use the scale=1.5 option in the \includegraphics command to resize the image to 150% of its original size. That is,
keepaspectratio
:
保持比例不变,一般调整长宽之一,然后让它自适应调整 --- [width=0.3,
keepaspectratio,angle=0] this will control the size of the figure,
change the fraction to your desired one. say 0.25, if do not wanna keep
the aspect ration same, use "height = 0.5 cm" like setting. you can
change the angular position as well.
\includegraphics[width=10cm,height=10cm,keepaspectratio]{image.png}
latex 跨文件引用
设定公式初始值: 在要设置的 eqation
前面,写:\setcounter{equation}{66}
,即从 66 开始作为 0
初始值。
在引用的文件里加上被引用的外部文件名:
1 | \usepackage{xr} |
Package caption Warning: Unsupported document class (or package) detected
在使用 IEEEtrans 模板时发现的报错,因为 IEEEtrans 模板重新定义了 caption 的格式,而我由于使用了 subfig 这个包,因此会覆盖掉 IEEE 的定义,因此,在 usepackage 时禁用掉 caption 定义就行
1 | \usepackage[caption=false]{subfig} |
参考: counters - Begin equation numbering with specific number - TeX - LaTeX Stack Exchange
Cross referencing with the xr package in Overleaf - Overleaf, Online LaTeX Editor
table
直接使用网页上的 LaTeX table generator 解决问题
末尾加
\hline
是横线\begin{tabular}{ccc}
是每栏居中,\begin{tabular}{|c|c|c|}
竖杠对应列的竖线加粗线
\usepackage{makecell}
and use
\Xhline{2\arrayrulewidth}
instead of
\hline
- 调整列表行距
1 | \begin{table} |
我的表列数比较多,双栏时放不下。可以将左边距设置小一点,类似调行距那个:
\renewcommand{\arraystretch}{1.3}%调行距
\setlength\tabcolsep{3pt}%调列距
参考 LaTex 技巧[43]:Latex 如何调整表格的行距-远方教程
注意在 latex .bib 中注释 @ 的句子是不管用的
@ 应该是特殊字符,注释不管用,会报错 bib 格式不对。
1 | % article{RS_1960, |
latex 表格加注释
参考
LaTex 技巧[43]:Latex 如何调整表格的行距-远方教程
公式
公式对齐
align
outside the math modealigned
inside the math mode,注意在在 \[\begin{equation}\end{equation}\] 之间用aligned
, markdown 中&
放在要对齐的位置
调整公式之间间距以及公式与上下文字间距:\vspace{1cm}
,[1cm]
填写的数字可正可负。
数学符号
带广播的矩阵与向量元素相乘
The elementwise/Hadamard product (∘) and the all-ones vector 𝟷 can be used to write your product as
或者
参考
省略号
和 是低位置省略号 Low dots 和中心位置省略号 centered dots 的 latex 命令, 是 amsmath 命令用来试图帮你在 和 中自动做决断的。
通常来讲中心省略 一般用在数学模式的中心线上的符号后面,例如加号 + 或者右箭头 -> , 而 一般用在标点符号的后面,例如句号“ .” or 逗号“ ,”。
algorithm 中的
\gets
操作符的两个操作数需要要位于 $$
之中,而且该 $$
之中是公式环境,不需要再写
$
:
\STATE $ftrusted_i \gets ReliabilityCheck({\tilde{W}_{i}^{t}},BC)$
for 循环, if 判断后面加可见注释
例如需要在 for 循环后注释 in parallel
的文字:
\FOR[\textbf{in parallel}]{worker $i = 1, \cdots, N$}
Latex add section bookmark for pdf
实现如下:在导言区中加入以下的一行命令:
1 | \usepackage[breaklinks,colorlinks,linkcolor=black,citecolor=black,urlcolor=black]{hyperref} |
hyperref 中各参数的作用参考以下链接:https://wenku.baidu.com/view/c73c48427cd184254b353572.html
LaTex 对 Replt letter 加颜色
LaTeX 对文字加颜色
\textcolor{red}{text}
注意包裹的 text
需要是一段文字不能换行。
LaTeX 对 Table 加颜色
在 caption 前面加 便是 blue 色
1 | \color{blue} |