Word
其实也蛮好用的,如果要精细排版,我还是会选择 word
。学一下 latex
主要是为后面用 Overleaf
写论文做一下铺垫, 再说技多不压身嘛。我还是要强调一个观点: 工具没有优劣之分, 同样算法也没有优劣之分,只有合适与否。
参考资料:Overleaf:Learn LaTeX in 30 minutes
1. 什么是 Latex
Latex
是用于创建 professional-looking
文档的工具。作者只需输入 palin text
(纯文本)即可以控制文档格式。
2. 第一个 latex 文档
在 overleaf
上新建一个blank project
, 输入下面代码:
\documentclass{article}
\begin{document}
First document. This is a simple example, with no
extra parameters or packages included.
\end{document}
第一行代码声明文档的类型。 documentclass
控制文档的 整体外观。在本例中的 article
是最简单和最常见的LATEX
文档 类。其他类型的文档可能需要不同的类,如 book
或report
。
在此之后,可以编写文档的 主体 内容,并将其封装在 \begin{document}
和 \end{document}
标记中。要在 PDF
中查看编写的结果,必须重编译文档, 点击 recomplie
按钮即可。
3. 文档序言
在上一个例子中,文本是在 \begin{document}
命令之后输入的。在此之前的 .tex
文件中的所有内容都称为 序言(preamble
)。在序言中,定义了正在编写的文档类型、正在编写的语言、希望使用的包 ( 稍后将对此进行更多介绍 ) 和其他一些元素。例如,一个普通的文档序言应该是这样的:
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
第一行 { } 定义了文档类型, [ ] 中的 12pt
定义了 font size
, letterpaper
定义了 paper size
。
第二行决定了文档的编码方式。
4. 添加标题,作者和日期
只需在文档 序言 中添加:
- \title {First document}
文档题目命名为: First document
- \ author {Hubert Farnsworth}
添加作者名字
- \ thanks {funded by the Overleaf team}
在页脚增加致谢。
\ date {February 2014}
可以手动输入,也可以在 { } 中输入 \today ,日期会与编译时刻自动同步。
综上, 文档序言部分会变成:
\documentclass[12pt, letterpaper, twoside]{article}
\usepackage[utf8]{inputenc}
\title{First document}
\author{Hubert Farnsworth \thanks{funded by the Overleaf team}}
\date{February 2017}
要显示标题,需要在文档的 主体 部分添加命令 \maketitle
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
\end{document}
![](https://img.haomeiwen.com/i9324289/018bd4bcbc3ce12d.png)
5.添加注释
在注释文字前添加 % 即可。
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
% This line here is a comment. It will not be printed in the document.
\end{document}
6. 粗体,斜体和下划线
Some of the \textbf{greatest}
discoveries in \underline{science}
were made by \textbf{\textit{accident}}.
![](https://img.haomeiwen.com/i9324289/1104800e45ada5d7.png)
命令 \emph 同样可以达到强调文本的目的, 其行为方式取决于上下文(context
)。当上下文是普通文本中, \emph 将目标文本转变为斜体, 当上下文是斜体文本时,则反之。
Some of the greatest \emph{discoveries}
in science
were made by accident.
\textit{Some of the greatest \emph{discoveries}
in science
were made by accident.}
\textbf{Some of the greatest \emph{discoveries}
in science
were made by accident.}
![](https://img.haomeiwen.com/i9324289/8e50b2e2a6c08528.png)
7. 添加图片
在 overleaf
界面左上角点击上传按钮,选择本地图片文件上传。
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {images/} }
\begin{document}
The universe is immense and it seems to be homogeneous,
in a large scale, everywhere we look at.
\includegraphics[width=4cm, height = 5cm]{haha.jpg}
There's a picture of a galaxy above
\end{document}
![](https://img.haomeiwen.com/i9324289/e112d5a580e1b5b9.png)
8. 图释,图题和图引用
当在 LATEX
文档中放置图像时,我们通常将它们放在 figure
环境中,以便 LATEX
能够将图像定位到适当的位置.
![](https://img.haomeiwen.com/i9324289/0085f8bfa5773d0a.png)
\begin{figure}[h]
\centering
\includegraphics[width=0.25\textwidth]{mesh}
\caption{a nice plot}
\label{fig:mesh1}
\end{figure}
As you can see in the figure \ref{fig:mesh1}, the
function grows near 0. Also, in the page \pageref{fig:mesh1}
is the same example.
![](https://img.haomeiwen.com/i9324289/9e00159839f18a41.png)
-
\caption{a nice plot}: 为图设置标题。
-
\label{fig:mesh1}: 如果需要在文档中引用图片,用这个命令设置一个标签。标签将图像进行编号,并允许您引用它。
-
\ref{fig:mesh1}: 此代码将被引用图对应的标签数字所替代。
9. 创建列表
- 无序列表
\begin{itemize}
\item The individual entries are indicated with a black dot, a so-called bullet.
\item The text in the entries may be of any length.
\end{itemize}
![](https://img.haomeiwen.com/i9324289/b17393684dc39bb1.png)
- 有序列表
\begin{enumerate}
\item This is the first entry in our list
\item The list numbers increase with each entry we add
\end{enumerate}
![](https://img.haomeiwen.com/i9324289/b883044708a6eb76.png)
10 数学公式
LaTeX
中的数学公式有两种书写模式,行内模式( inline mode
)和行间模式(display mode
)。公式若出先在文本段中,则使用行内模式,否则使用行间模式。
- 行内模式
只需将公式用 \(...\), 或 $...$, 或 \begin{math}...\end{math} 包起来即可。
In physics, the mass-energy equivalence is stated
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.
![](https://img.haomeiwen.com/i9324289/2133bcee42fd096b.png)
- 行间模式
只需将公式用 \[ ... \] 或 \begin{displaymath} ... \end{displaymath} 或 \begin{equation} ... \end{equation} 包起来即可。
The mass-energy equivalence is described by the famous equation
\[E=mc^2\]
discovered in 1905 by Albert Einstein.
In natural units ($c = 1$), the formula expresses the identity
\begin{equation}
E=m
\end{equation}
![](https://img.haomeiwen.com/i9324289/89675349999340e5.png)
11 基本格式
挺繁复的,用时再查,30min
入门时间已过,收工回家睡觉。全世界晚安。
网友评论