LaTeX Cookbook by Eric

1. LaTeX编译环境——TeXstudio

使用TeXstudio来编译LaTex文件;

Note
目前没有使用Overleaf,因为Overleaf暂时不支持JabRef文献导入。

关于LaTeX编译环境安装,请参考博文《LaTeX写作》——LaTeX编写环境的安装笔记

1.1 界面介绍

侧边栏:导航文档结构

操作路径:ViewShowSide Panel

1.2 快捷键

Short keyAction
Ctrl + T注释选中行

1.3 Troubleshooting

(1)构建(Build)时提示“xxx.bbl 错误 Something’s wrong–perhaps a missing \item. \end{thebibliography}”

在TeXstudio中,这个错误通常发生在参考文献(bibliography)部分,可能的原因:

  1. 项目中没有.bib文件;
  2. 存在ref.bib文件,但是此文件尚未进行编译;

首先需要确认项目中已经添加.bib文件,然后进行编译
操作路径:菜单栏工具参考文献(Bibliography)
然后就可以构建文档了;

2. 字体设置

粗体

\textbf{粗体文字}

引用文字

\textit{This is a quoted text.}

3 标点符号

空格~
双引号:前后引号``"
在这里插入图片描述
(感谢夕小瑶公众号,配图来自博文“夕小瑶整理:论文写作中注意这些细节,能显著提升成稿质量”
波浪线\textasciitilde

4 图示

格式: .eps
绘图工具: PowerPoint

插图instant代码

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{figure_file.eps}
	\caption{Figure_Title}
\end{figure}

插图示例代码

\begin{figure}[htbp]
	\centering
	\includegraphics[width=\textwidth]{figure_file.eps}
	\caption{Figure_Title}
\end{figure}

figure*: *表示双栏,不加*就是单栏。(对于表格和公式也是这样)
图示位置参数一般写作:[htbp]
位置参数说明:

  • H:强制将图片放在当前位置。
  • h:当前位置(尝试),但不保证一定会放在当前位置。
  • t:顶部。
  • b:底部。
  • p:浮动页。

4.1 图片文件目录管理

请参考知乎——“LaTeX 如何插入图片——入门教程”

4.2 竖排多图(子图)

横排(ab)子图

使用subfloat实现横排多个子图:

\usepackage{subfig} % 引入subfloat
\begin{figure}[!htbp]
	\centering %使插入的图片居中显示
	\subfloat[Figure1]{\includegraphics[width=0.5\linewidth,clip]{fig.eps}
		\label{fig1}}
	\subfloat[Figure2]{\includegraphics[width=0.5\linewidth,clip]{fig.eps}
		\label{fig2}}
	\caption{Procedure of the method.}
	\label{fig_method}
\end{figure} 

竖排(ab)子图

使用subfloat实现竖排并列的多个子图:

\usepackage{subfig} % 引入subfloat
\begin{figure}[!htbp]
	\centering %使插入的图片居中显示
	\subfloat[Figure1]{\includegraphics[width=\linewidth,clip]{fig.eps}
		\label{fig1}}
	\\ % 换行符
	\subfloat[Figure2]{\includegraphics[width=\linewidth,clip]{fig.eps}
		\label{fig2}}
	\caption{Procedure of the method.}
	\label{fig_method}
\end{figure} 

4.3 使用clip去除图片周围的空白

使用clip去除图示周围的空白,即:

[width=\textwidth,clip]

在这里插入图片描述

5 表格

基本格式:

\begin{table}
	\centering % 表示居中
	\begin{tabular}{|c|c|c|c|}
		\hline
		\multicolumn{2}{|c|}{合并一行两列} & 三 & 四 \\
		\hline
		1 & 2 & 3 & 4 \\
		\hline
	\end{tabular}
\end{table}

Note:如果出现文字无法对齐的情况,对表格中加粗的文字请使用\textbf{},而不要使用\bf{}

5.1 合并单元格

请参考《Latex 表格技巧 - 合并单元格》

合并一行多列

\begin{table}
	\centering
	\begin{tabular}{|c|c|c|c|}
		\hline
		\multicolumn{2}{|c|}{合并一行两列} && 四 \\
		\hline
		1 & 2 & 3 & 4 \\
		\hline
	\end{tabular}
\end{table}

合并一列多行\multirow

\begin{table}[htbp]
	\centering
	\caption{Caption}
	\begin{tabular}{c c c c c c}
		\hline
		\multirow{2}*{\textbf{架构}} & \multirow{2}*{\textbf{参数}} & \multicolumn{4}{c}{\textbf{数据集}}\\
		\cline{3-6}
		~ & ~ & \textbf{} & \textbf{} & \textbf{} & \textbf{}\\ 
		\hline
		Architecture & Params  & 1 & 2 & 3 & 4\\
		\hline
	\end{tabular}
\end{table}

6 列表

无序列表

% 不需要引入第三方包
\begin{itemize}
	\item 第一项内容
	\item 第二项内容
	\item 第三项内容
	\item item\_category\_id:代码中遇到“\_”,需要进行转义才能正常显示。
\end{itemize}

列表项加粗

\begin{itemize}
	\item 
	\textbf{列表项1:}第一项说明。
	\item 
	\textbf{列表项2:}第二项说明。
	\item 
	\textbf{列表项3:}第三项说明。
\end{itemize}

自由编号列表

\begin{itemize}
\itemindent 4em
\item[(1)] Aaa aaa.
\item[(2)] Bbb bbb.
\item[(3)] Ccc ccc.
\end{itemize}

7 数学公式

插入公式的代码如下

\begin{equation}
a = 1,
\end{equation}

7.1 标点符号

公式中的省略号使用\ldots
例如: 1 , 2 , … , n 1,2,\ldots,n 1,2,,n

括号的基本格式:\left( y \middle| x \right) ( y | x ) \left( y \middle| x \right) (yx)
常用的括号:() <> || .
这里的\middle|表示条件概率;

对于超过一个字母的变量或符号,要用正文字体,需要使用LaTeX已有的符号或者正文样式,
常用数学表达式:\arg, \max, \sin, \cos, \tan
正文样式:\text{pred}, \text{true}

7.2 公式对齐

可以使用align关键字进行公式对齐;

等号对齐

对齐方式:在等号前面加上&

7.3 条件方程:\begin{cases}

W i j = { log ⁡ ( a m ) ( i , j ) ∈ A m 0 ( i , j ) ∉ A W_{ij} = \begin{cases} \log(a_m) & (i,j) \in A_m \\ 0 & (i,j) \notin A \end{cases} Wij={log(am)0(i,j)Am(i,j)/A

8 插入代码

请参考文章《Latex 插入代码(Matlab 或 Python)》
可以参考伍老师PPT,使用algorithm2e命令包;
代码示例:

\begin{algorithm}[htbp]
\KwIn{$N$ labeled training examples, $\{(\mathbf{x}_n,y_n)\}^N_{n=1}$,
where $\mathbf{x}_n\in\mathbb{R}^{M\times 1}$\;
\hspace*{9mm} $T$ unlabeled examples, $\{\mathbf{x}_t\}_{t=1}^T$\;}
\KwOut{The PL model predictions for $\{\mathbf{x}_t\}_{t=1}^T$.}
\tcp{Train the PL model}
Train a global fuzzy model using all $N$ training examples\;
\For{$m=1,...,M$}
{Identify the first-order rule partitions for the $m$th input domain of the
global fuzzy model\;}
Index the partitions using $k$ in (\ref{eq:k})\;
Include all partitions in the candidate pool\;
$l=1$\;
\While{$l\le L$}{
Identify from the candidate pool the partition giving the maximum SSE\;
Record the location of the partition as the $l$th patch\;
Train a patch fuzzy model using only the training examples within the
$l$th patch\;
\If{the $l$th model is successfully trained\footnotemark{}}
{$l=l+1$\;}
Remove the above patch from the candidate pool\;}
\caption{PL using fuzzy systems.} \label{alg:PLFS}
\end{algorithm}

伪代码效果图:
在这里插入图片描述

使用格式化包美化显示python代码

请参考博文《不一样的 LaTeX 教程:使用 listings 宏包美化代码》

9 参考文献

管理工具: JabRef

9.1 参考文献连号显示

如果参考文献需要连号显示,例如:“[5, 6]”,
而默认模板是分开显示的“[5] [6]”,则需要加入格式包来进行设置,
在代码声明中加入如下包声明,

\usepackage[numbers,sort&compress]{natbib}

9.2 强制文献条目刊名字母大写

有两种方式:

  • 使用JabRef的工具自动进行转换。
  • 使用花括号{}指定大写单词。

9.3 Troubleshooting

(1)TeXstudio提示error: “Citation xxx on page xx undefined”

这个错误提示的意思是,Citation表达式未定义,可能的原因是,
修改文献ID后,IDE还没有重新进行载入
此时,就重新Build一次,看文献引用是否能正常显示;
如果重新构建后,TeXstudio提示"No file TeXFileName.bbl.",并且引用仍是未定义
则需要对.bbl文件单独进行编译,
操作路径:ToolsBibliography
然后在重新对tex文件进行构建;

10 引用编号

在引用编号的时候,首先需要用\label指定元素的名称;
对象引用:\ref{}
文献引用:\cite{}
例如:

% 引用章节
\section{Section1}
\label{sec:context1}
The section number is \ref{sec:context1}.
% 引用公式
So the formula is \ref{eq_formula1}.

11 模板备注

8.1 IEEE模板

Latex编译器:pdflatex (可以支持.png图片格式)

12 LaTeX论坛提问

可以通过以下几种方式进行提问:

  1. 在搜索的博文下面提问,可以提问3个博文;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值