LaTeX Cookbook by Eric

本文介绍了使用TeXstudio作为LaTeX编译环境的配置与使用,包括界面、快捷键和故障排查。讲解了字体设置、标点符号、图片插入与管理、表格制作、列表创建、数学公式以及参考文献的处理。同时,提供了代码示例和解决编译错误的方法,是 LaTeX 初学者的实用教程。
摘要由CSDN通过智能技术生成

LaTeX学习教程

Learn LaTeX in 30 minutes: Including title, author and date information

1. 常见术语

1.1 TeX Live:LaTeX语言的编译环境

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个博文;
Over 90 hands-on recipes for quickly preparing LaTeX documents to solve various challenging tasks Book Description LaTeX is both a word processor and a markup language. It's pretty simple really, which is why its unsurprising that its so popular within the research community - whether you're a scientist or statistician, with LaTeX, you'll find it easy to present and communicate your work - it gives you full control of the documents you create, no matter how complex they might be. With a huge range of customizable templates and supporting packages available, there's plenty to explore - so you can make LaTeX work for you. LaTeX Cookbook shows you how to get the most from LaTeX - so you can focus on what's important. Inside, you'll find everything from different templates and document types, samples for fine-tuning text design, guidance through embedding images, as well as drawing tables in LaTeX. With essential components to the modern research document included, such as creating a bibliography, glossary, and index, you can be confident that your document is clean and clear. You will also learn how to create graphics within LaTeX, and find vital tips to help you build diagrams with minimum fuss. If that isn't enough, the book also shows you how to use new engines XeTeX and LuaTeX which give LaTeX further functionality so you can handle any complexity with ease and elegance. If you're worried about presenting or communicating ideas and research for maximum impact, look no further than this book - it's sure to increase your productivity.
LaTeX CookbookPaperback Paperback: 378 pages Publisher: Packt Publishing - ebooks Account (October 28, 2015) Language: English ISBN-10: 1784395145 ISBN-13: 978-1784395148 Over 100 hands-on recipes to quickly prepare LaTeX documents of various kinds to solve challenging tasks About This Book Work with modern document classes, such as KOMA-Script classes Explore the latest LaTeX packages, including TikZ, pgfplots, and biblatex An example-driven approach to creating stunning graphics directly within LaTeX Who This Book Is For If you already know the basics of LaTeX and you like to get fast, efficient solutions, this is the perfect book for you. If you are an advanced reader, you can use this book's example-driven format to take your skillset to the next level. Some familiarity with the basic syntax of LaTeX and how to use the editor of your choice for compiling is required. What You Will Learn Choose the right document class for your project to customize its features Utilize fonts globally and locally Frame, shape, arrange, and annotate images Add a bibliography, a glossary, and an index Create colorful graphics including diagrams, flow charts, bar charts, trees, plots in 2d and 3d, time lines, and mindmaps Solve typical tasks for various sciences including math, physics, chemistry, electrotechnics, and computer science Optimize PDF output and enrich it with meta data, annotations, popups, animations, and fill-in fields Explore the outstanding capabilities of the newest engines and formats such as XeLaTeX, LuaLaTeX, and LaTeX3
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值