Latex学习笔记二——Overleaf在线练习

 

锵锵~本文是基于Overleaf的Latex学习的第二部分。


目录

1. 结构化文档

2. 添加图表,让论文更生动可读

2.1 Graphics

2.2 Floats

2.3 Tables

3. Bibliographies


1. 结构化文档

这一部分更像是论文的写作,包括标题、摘要、引用等内容

\documentclass{article} %告诉Latex文档类型为Article
\title{The Title} %{}里面是标题
\author{A. Author}%{}作者
\date{\today} %{\today}Latex会智能的显示文档编辑时的日期
\begin{document} %开始写文档
\maketitle %在文档中显示之前写好的标题
\begin{abstract} %摘要部分从下面开始,注意,这里{}内就是abstract,不要改
Abstract goes here...
\end{abstract}
\end{document}

运行结果:

Latex学习笔记二——Overleaf在线练习_第1张图片

接下来,我们尝试为论文添加Introduction, Method, Results等部分:

\documentclass{article}
\begin{document}
\section{Introduction}
The problem of \ldots
\section{Method}
We investigate \ldots
\subsection{Sample Preparation}
\subsection{Data Collection}
\section{Results}
\section{Conclusion}
\end{document}

注意:\section不需要\end{section}。

运行结果:

Latex学习笔记二——Overleaf在线练习_第2张图片

好~,至此,论文的框架有了,那么如果我们想在文中(尤其是摘要中),介绍我们这几个部分的大体内容或提到我们的某个公式时,该怎么样显得好看又不会出错呢?接下来就是 \label 和 \ref大显身手的时候啦(要引用公式的话,需要用到 \eqref 即 equation reference)

\documentclass{article}
\usepackage{amsmath} % for \eqref
\begin{document}
\section{Introduction}
\label{sec:intro}
In Section \ref{sec:method}, we \ldots
\section{Method}
\label{sec:method}
\begin{equation}
\label{eq:euler}
e^{i\pi} + 1 = 0
\end{equation}
By \eqref{eq:euler}, we have \ldots
\end{document}

运行结果:

Latex学习笔记二——Overleaf在线练习_第3张图片

到这一步就把Overleaf官网上Free online introduction to LaTeX (part 2)的第一部分Structured Documents的知识点都练习一遍了,在随后附上的Exercise中,我犯了一个错误:在要引用处写的是 \label{...}

正确的写法应该是:\ref{...},在被引用的地方才是要给加label之处。

下面,贴出第一篇正儿八经自己打的Latex论文:

\documentclass{article}
\usepackage{amsmath}
\title{The Relationship Between the UNIVAC Computer and Evolutionary Programming}
\author{Bob, Carol and Alice}
\date{February 20, 2014}
\begin{document}
\maketitle

\begin{abstract}
    Many electrical engineers would agree that, had it not been for online algorithms, the evaluation of red-black trees might never have occurred. In our research, we demonstrate the significant unification of massive multiplayer online role-playing games and the location-identity split. We concentrate our efforts on demonstrating that reinforcement learning can be made peer-to-peer, autonomous, and cacheable.
\end{abstract}

\section{Introduction}

Many analysts would agree that, had it not been for DHCP, the improvement of erasure coding might never have occurred. The notion that hackers worldwide connect with low-energy algorithms is often useful. LIVING explores flexible archetypes. Such a claim might seem unexpected but is supported by prior work in the field. The exploration of the location-identity split would profoundly degrade metamorphic models.

The rest of this paper is organized as follows. In section \ref{sec:method}, we describe the
methodology used. In section \ref{sec:conc} we conclude.

\section{Method}
\label{sec:method}

Virtual methods are particularly practical when it comes to the understanding of journaling file systems. It should be noted that our heuristic is built on the principles of cryptography. Our approach is captured by the fundamental equation \eqref{eq:fundamental}.
\begin{equation}
    E = mc^{3} \label{eq:fundamental}
\end{equation}
     Nevertheless, certifiable configurations might not be the panacea that end-users expected. Unfortunately, this approach is continuously encouraging. Certainly, we emphasize that our framework caches the investigation of neural networks. Thus, we argue not only that the infamous heterogeneous algorithm for the analysis of the UNIVAC computer by Williams and Suzuki is impossible, but that the same is true for object-oriented languages.

\section{Conclusions}

\label{sec:conc}

Our contributions are threefold. To begin with, we concentrate our efforts on disproving that gigabit switches can be made random, authenticated, and modular. Continuing with this rationale, we motivate a distributed tool for constructing semaphores (LIVING), which we use to disconfirm that public-private key pairs and the location-identity split can connect to realize this objective. Third, we confirm that A* search and sensor networks are never incompatible.

\end{document}

2. 添加图表,让论文更生动可读

2.1 Graphics

一开始,Overleaf指导PPT里面插入图片的代码里面没有说明,我们要用到的图片被保存在了哪里。无奈,在网上搜了搜Latex插入图片路径设置的方法,发现答案基本都是引自同一位作者的,而且都没有说清楚。没办法,只好摸索着来了。

首先,我们先把代码保存一下,就按默认保存地址保存就好。我的地址如下:

这就是Texstudio默认保存.tex文档的地址(.tex文档是标准Latex编辑器保存的文档格式,就像Matlab保存的文件后缀名是.m,python的是.py一样)。

把要插入到文中的图片复制到上面的地址下

Latex学习笔记二——Overleaf在线练习_第4张图片

代码如下:

\documentclass{article}
\usepackage{graphicx} %图片需要导入宏包:graphicx
%\graphicspath{{\Application\texlive\2019\texmf-dist\tex\latex\base/}}
\begin{document}
Figure \ref{fig:gerbil} shows \ldots
\begin{figure}[htbp]%%不得了:这一行如果有[htbp],显示的就是图片在文字“Figure ?? shows”下面哎,如果去掉[htbp]的话则刚好相反!!!
\centering %居中显示嘛
\includegraphics[
width=0.5\textwidth]{Music_Future}
\caption{\label{fig:gerbil}Aww\ldots.}%给图片加题注
\end{figure}
\end{document}

显示结果:

Latex学习笔记二——Overleaf在线练习_第5张图片

不过如果将图片直接放在这个目录下的话,这个base文件夹里面就会很乱。我们不妨在base文件夹下再设一个fig文件夹,将图片都放进去。比如这样:

Latex学习笔记二——Overleaf在线练习_第6张图片

Latex学习笔记二——Overleaf在线练习_第7张图片

代码也需要相应稍微改动一下:

\documentclass{article}
\usepackage{graphicx}
%\graphicspath{{\Application\texlive\2019\texmf-dist\tex\latex\base/}}
\begin{document}
Figure \ref{fig:gerbil} shows \ldots
\begin{figure}%%不得了:这一行如果有[htbp],显示的就是图片在文字“Figure ?? shows”下面哎,如果去掉[htbp]的话则刚好相反!!!
\centering %居中显示嘛
\includegraphics[
width=0.5\textwidth]{fig//Music_Future}
\caption{\label{fig:gerbil}Aww\ldots.}%给图片加题注
\end{figure}
\end{document}

显示如图:

Latex学习笔记二——Overleaf在线练习_第8张图片

不知道大家发现没有,我这一次故意把[htbp]去掉了,文字和图片的位置就颠倒了。代码里面需要改变的也只有一句:

width=0.5\textwidth]{fig//Music_Future}

只需要在图片名字前面写清楚base文件夹下的保存有我们需要图片的子文件夹的名字就可以啦!

但是!!!

一定要注意,子文件夹名和图片名之间是//,而不是\\。

哦哦哦,[htbp]参考这篇文章:https://www.cnblogs.com/bingo711x/p/6097902.html 知道了部分含义——

h:当前位置

b:优先排在底部

t: 优先排在每页顶部

!: 加入感叹号表示强制性

另外一种定义路径的方法是使用\graphicspath设置单或多个路径。

如:\graphicspath{{imagepath1/}{imagepath2/}…{imagepathn/}}

参考:https://herechen.github.io/technology/latex-skills/#%E7%BB%98%E5%9B%BE

\documentclass{article}
\usepackage{graphicx}
	\graphicspath{{fig/}{fig/EXE/}}
\begin{document}
Figure \ref{fig:Music_Future} shows \ldots
\begin{figure}

\centering %居中显示嘛
\includegraphics[
width=0.5\textwidth]{Music_Future}
\caption{\label{fig:Music_Future}Aww\ldots.}%给图片加题注

\end{figure}
Figure \ref{fig:gerbil} shows \ldots

\begin{figure}

	%% h:当前位置	b:优先排在底部	t: 优先排在每页顶部	!: 加入感叹号表示强制性
	\centering %居中显示嘛
	\includegraphics[
	width=0.3\textwidth,
	angle=270]{gerbil}%图片旋转270°
	
\end{figure}

\end{document}

运行结果:

Latex学习笔记二——Overleaf在线练习_第9张图片

2.2 Floats

根据官方的说法:

  • Allow LATEX to decide where the figure will go (it can “float”).
  • You can also give the figure a caption, which can be referenced with \ref.
    \documentclass{article}
    \usepackage{graphicx}
    \begin{document}
    	Figure \ref{fig:gerbil} shows \ldots
    	\begin{figure}
    		\centering
    		\includegraphics[%
    		width=0.5\textwidth]{fig//EXE//gerbil}
    		\caption{\label{fig:gerbil}Aww\ldots.}
    	\end{figure}
    \end{document}

    同样的,要记得先保存代码再编译运行哦!

Latex学习笔记二——Overleaf在线练习_第10张图片

 

2.3 Tables

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\begin{tabular}{lrr}
	Item & Qty & Unit \$ \\
	Widget & 1 & 199.99 \\
	Gadget & 2 & 399.99 \\
	Cable & 3 & 19.99 \\
\end{tabular}
\begin{tabular}{|l|r|r|} \hline
	Item & Qty & Unit \$ \\\hline
	Widget & 1 & 199.99 \\
	Gadget & 2 & 399.99 \\
	Cable & 3 & 19.99 \\\hline
\end{tabular}
\end{document}

运行结果:

Latex学习笔记二——Overleaf在线练习_第11张图片

官方文档:

Use an ampersand & to separate columns and a double backslash \ \ to start a new row (like in the align*
environment that we saw in part 1).

在Latex中,用&来隔开每一列,用\\表示重启一行书写。

3. Bibliographies

在Latex里面引用的话,首先需要建立一个引用文本的库。具体操作步骤是:打开Texstudio,新建一个文件,把要引用的文献的BibTex格式内容都放进去,如:

@Article{Jacobson1999Towards,
	author = {Van Jacobson},
	title = {Towards the Analysis of Massive Multiplayer Online
	Role-Playing Games},
	journal = {Journal of Ubiquitous Information},
	Month = jun,
	Year = 1999,
	Volume = 6,
	Pages = {75--83}}

@InProceedings{Brooks1997Methodology,
	author = {Fredrick P. Brooks and John Kubiatowicz and
	Christos Papadimitriou},
	title = {A Methodology for the Study of the
	Location-Identity Split},
	booktitle = {Proceedings of OOPSLA},
	Month = jun,
	Year = 1997}

@Article{Sutherland2003UNIVAC,
	author = {{Ivan} {Sutherland} and {H}. {Nehru}},
	title = {The {UNIVAC} Computer No Longer Considered Harmful},
	journal = {{Journal} of Distributed Models},
	Month = jan,
	Year = 2003,
	Volume = 6,
	Pages = {153--196}}

@InProceedings{Taylor2003Influence,
	author = {{O}. {Taylor}},
	title = {The Influence of Concurrent Archetypes on Networking},
	booktitle = {{Proceedings} of {PODS}},
	Month = may,
	Year = 2003}

@InProceedings{Karthik2001Analysis,
	author = {{Karthik} {Lakshminarayanan}},
	title = {An Analysis of Forward-Error Correction Using {MollSextans}},
	booktitle = {{Proceedings} of the {Symposium} on Stable Configurations},
	Month = jun,
	Year = 2001}

@Techreport{Smith1990Enabling,
	author = {{J}. {Smith} and {Leonard} {Adleman}},
	title = {Enabling the Transistor Using Secure Algorithms},
	institution = {{IBM} {Research}},
	number = {99-74-1618},
	Month = mar,
	Year = 1990}

Latex学习笔记二——Overleaf在线练习_第12张图片

 

 

保存为Tex文件,后缀名为.bib:

Latex学习笔记二——Overleaf在线练习_第13张图片

然后在.tex文件中写如下命令:

\documentclass{article}
\usepackage{natbib}
\begin{document}
	\citet{Brooks1997Methodology}
	show that \ldots. Clearly,
	all odd numbers are prime
	\citep{Jacobson1999Towards}.
	\bibliography{refbib}
	% if `bib-example' is the name of
	% your bib file
	\bibliographystyle{plainnat}
	% try changing to abbrvnat
\end{document}

一定要看清楚,在\bibliography{}里面写上自己保存的.bib文件的名字哦,不要带上后缀名。

运行结果:

Latex学习笔记二——Overleaf在线练习_第14张图片


呼~以上就是Part 2的全部内容啦!希望对大家学习Latex有帮助~

 

 

 

你可能感兴趣的:(Latex学习,学习笔记)