Latex on overleaf入门语法

前言

感谢参考文献:
Overleaf 指南:30 分钟 LaTeX 入门

基本结构

\documentclass{article} % 声明文档的类型为article

\begin{document}
First document. This is a simple example, with no
extra parameters or packages included.
\end{document}
  1. \documentclass{article}:声明文档的类型为article。
  2. begin前面:文档的序言。
  3. begin和end之间是文档的主体body。

序言

定义文档的字体大小,纸张大小,文档编码为utf-8。

\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}

标题、作者、日期

序言中还可以添加标题、作者和日期。在主体body中可以打印这些信息,使用\maketitle

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the Overleaf team}}
\date{February 2017}

一个比较复杂的\author格式:

\author{
    \IEEEauthorblockN{Hua Li\textsuperscript{1},  Alice Chen\textsuperscript{1*}}
\IEEEauthorblockA{\textsuperscript{1}\textit{ABC University} \\
\textit{China} \\
*Corresponding Author: Alice Chen, Email: 123@abc.edu.cn}
}
  • IEEEauthorblockN{}:IEEEtran文档类特有的命令,用于定义作者的名字和隶属机构的编号。
  • \textsuperscript{1}:将1作为上标显示,表示作者隶属于同一个机构。
  • \IEEEauthorblockA{}:IEEEtran文档类特有的命令,用于定义作者的隶属机构和联系信息。
  • \\:换行符。

简单的格式化命令

添加注释:%

加粗、斜体、下划线、百分号

强调文本命令:展现的效果取决于上下文,斜体or普通文本。
et al.好像需要加斜体\textit{}

加粗:\textbf{}
下划线:\underline{}
斜体:\textit{}
百分号:\%

强调文本:\emph{}

有序列表、无序列表

使用不同的环境 environment来创建不同形式的列表,环境以\begin{}开始,以\end{}结束。

无序列表使用itemize环境,每个条目之前要加\item,各个条目默认用黑点表示。

\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}

有序列表使用enumerate环境。

\begin{enumerate}
  \item This is the first entry in our list
  \item The list numbers increase with each entry we add
\end{enumerate}

添加图片

\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{universe}

There's a picture of a galaxy above
\end{document}

  1. 添加图片需要使用包 package,在序言中添加\usepackage{graphicx}表示导入包,\graphicspath{{images/} }表示图像所在的根目录为:当前目录下名为 images 的文件夹中。
  2. \includegraphics {universe}:在文档中引入图像。图像文件名不带扩展名,文件名不应该包括空格和多个点。

图片的标题、标签和引用

\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.
  1. 将图片放在 figure 环境中,才可以添加标题、标签和引用。具体命令为:\begin{figure}[h]\end{figure}。若希望图片占页面的双栏,则需要使用\begin{figure*} ... \end{figure*}环境。
  2. \caption{}:为图片设置标题。此命令可以放在图片的上方或下方。
  3. \label{fig:mesh1}:为图片设置标签,标签可以为图片编号,方便后续在文章中引用该图片。
  4. \ref{fig:mesh1}:编译后显示被引用图片的编号。

控制图片位置

常用选项[htbp]是浮动格式:

  • h:here,当前位置。将图形放置在正文文本中给出该图形环境的地方。如果本页所剩页面不够,这一参数将不起作用。
  • t:top,页面顶部。
  • b:buttom,页面底部。
  • p:page of its own,浮动页。将图形放置在一个允许有浮动对象的页面上。

一般使用[htb]的组合。
当表格或者图片占据双栏模板的两栏时,这些控制选项就失效了。若想放置在页面顶部,用[ht]。若想放置在页面底部,导言区加入\usepackage{stfloats} 用,并且位置参数使用[bp]

子图

一个由2行4列子图构成的图片latex语法为:

\begin{figure}[thb]
    \centering
    
    \resizebox{0.5\textwidth}{!}{
    \subfigure[aaa]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/1.jpg}\label{fig: sub_figure1}}\hspace{0.1cm}
    \subfigure[bbb]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/2.jpg}\label{fig: sub_figure2}}\hspace{0.1cm}
    \subfigure[ccc]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/3.jpg}\label{fig: sub_figure3}}\hspace{0.1cm}
    \subfigure[ddd]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/impurity_figs/4.jpg}\label{fig: sub_figure4}}
    }
    
    \vspace{0.1cm}
    \resizebox{0.48\textwidth}{!}{
    \subfigure[eee]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/5.jpg}\label{fig: sub_figure5}}\hspace{0.1cm}
    \subfigure[fff]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/6.jpg}\label{fig: sub_figure6}}\hspace{0.1cm}
    \subfigure[ggg]{\includegraphics[width=0.23\textwidth, height=0.24\hsize]{figs/7.jpg}\label{fig: sub_figure7}}\hspace{0.1cm}
    \subfigure[hhh]{\includegraphics[width=0.24\textwidth, height=0.24\hsize]{figs/8.jpg}\label{fig: sub_figure8}}
    }
    
    \caption{Examples}
    \label{fig: figure1}
\end{figure}
  • \centering:设置接下来的文本居中对齐。
  • \resizebox{0.5\textwidth}{!}{...}:调整盒子内内容的大小。0.5\textwidth表示盒子宽度设置为页面宽度的50%。!表示保持图片的宽高比。
  • \subfigure[]{}:创建子图。[]内是子图的caption,{}内是图片的信息和标签。
  • \vspace{}\hspace{}:在元素之间添加垂直空间和水平空间。

添加表格

一个简单的表格

创建表格的默认环境是tabular,必须给该环境传递一个参数{c c c}。该参数表示表格有 3列,每列文本均居中。除了c,还有r表示右对齐,l表示左对齐。
&表示分隔符,\\表示转到表格的下一行。

\begin{center}
\begin{tabular}{ c c c }
 cell1 & cell2 & cell3 \\
 cell4 & cell5 & cell6 \\
 cell7 & cell8 & cell9
\end{tabular}
\end{center}

为表格添加边框

\begin{center}
\begin{tabular}{ |c|c|c| }
 \hline
 cell1 & cell2 & cell3 \\
 cell4 & cell5 & cell6 \\
 cell7 & cell8 & cell9 \\
 \hline
\end{tabular}
\end{center}
  1. \hline:水平线命令,插入一条水平线。
  2. { |c|c|c| }|表示垂直线分隔。

标题、标签、引用

Table \ref{table:data} is an example of referenced \LaTeX{} elements.

\begin{table}[h!]
\centering
\scalebox{0.65}{

\begin{tabular}{||c c c c||}
 \hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \hline\hline
 1 & 6 & 87837 & 787 \\
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex]
 \hline
\end{tabular}

}
\caption{Table to test captions and labels}
\label{table:data}
\end{table}
  1. \caption{}:标题。
  2. \label{table:data}:标签。
  3. \ref{table:data} :引用。
  4. \scalebox{0.65}{...}:第一个{}内是缩放比例,第二个{}内一般是tabular对象/ tabularx对象。可以把整张表格等比例缩小。

合并单元格

合并多列

\multicolumn{14}{c|}{\textbf{Sub-Domains}}
  • 第一个{}:表示合并了14列。
  • 第二个{}:表示设置为居中对齐,并且该列的右侧添加竖线。
  • 第三个{}:该单元格里的文字。

合并多行多列

\multirow{2}{*}{\textbf{Model}}
  • 第一个{}:表示合并了2行。
  • 第二个{}:指定合并单元格的宽度,*表示自动计算宽度以适应内容。
  • 第三个{}:表示显示在单元格里的内容。

其他琐碎的表格语法

  1. tabularx对象:

X表示该列可以自动换行。tabularx对象中还允许你定义自己的列类型。

\begin{tabularx}{\textwidth}{lX}
...
\end{tabularx}
  1. specialrule对象:

配合\usepackage{booktabs}一起使用。用于在表格里添加水平线。
第一个{}里表示线的粗细,设置为0em表示线是透明的。第二个{}里表示线上方的空隙。第三个{}里表示线下方的空隙。可以通过调节第二、三个括号里的参数来调整空白间距。

\specialrule{0em}{2pt}{3pt}

数学表达式

数学表达式有两种模式:内联模式 inline,显示模式 display。

内联模式:公式是文本的一部分。以下3种定界符作用相同。

$...$
\(...\)
\begin{math}...\end{math}

显示模式:编号和非编号。

# 编号
\begin{equation}
...
\end{equation}

# 非编号
\[... \]

equation环境由外部包 amsmath提供。许多数学表达式都使用了这个包。

基本的数学命令

上标:$a^2$
下标:$H_2O$
积分:$\int$ 
分数:$\frac{a}{b}$
小写希腊字母:$\omega$ $\delta$
大写希腊字母:$\Omega$ $\Delta$
数学运算符的前缀为反斜杠:$\sin(x)$, $\cos(x)$, $\log(x)$

基本格式

摘要

摘要内容要在abstract环境中写。

\begin{document}

\begin{abstract}
This is a simple paragraph at the beginning of the
document. A brief introduction about the main subject.
\end{abstract}

\end{document}

段落、新行

开启新段落,需要输入两次 Enter键,以插入双空行。此时,Latex会为新段落自动缩进。

章节、分段

基本的标题级别如下所示,从上到下为从大到小的标题。在{}内设置标题,标题的编号是自动的。也可以在命令中加*来禁止编号。

\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\paragraph{paragraph}
\subparagraph{subparagraph}

\section*{Unnumbered Section}

引用参考文献

参考博客:
overleaf Latex bibtex单篇及多篇参考文献引用设置
overleaf使用bib tex引用参考文献教程

祖传用法:

\usepackage{cite}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

\bibliographystyle{IEEEtran}
\bibliography{ref}

引用命令: \cite{ref1}
在一处地方引用多篇参考文献:\cite{文献名称1, 文献名称2, ..., 文献名称n}
# 超过2篇文献,就会自动生成破折号
# 在ref.bib文件里写bibtex格式的papers,正文中直接cite,文章末尾会自动生成参考文献列表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值