ShareLatex速成(二)

ShareLatex速成(二)

第一次用ShareLatex

进入网站之后完成注册,点击左上角New Project开始我们的第一个项目,点击后勾选blank project。
现在我们看到网页左半部分显示了如下的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{First project}
\author{你的名字 }
\date{当前时间}

\begin{document}
\maketitle
\section{Introduction}

\end{document}

LaTeX用

\begin{document},\end{document}

分别用来告诉编译系统开始和结束文章,我们所有的正文内容必须写在这两者之间否则不会显示。
\section{}可以用来开启一个新的文章部分,括号内为这部分的标题,这里面写了introduction,你可以按你所想的修改他的内容。当你想填充内容时,只需要在\section{}部分下写上你想写的内容即可,比如这里我的代码写成了这样:

\begin{document}

\maketitle

\section{Introduction}
This is my first LaTeX sentence.

\end{document}

然后点击右半页版面上的这个图标就可以编译
这里写图片描述
这时我们可以看到网页右半页面显示的页面变成了:
这里写图片描述
如果我的Introduction下还细分了很多小部分的内容需要把他们通过小标题分开,但同时都在Introduction之下,这时我可以选择用指令subsection,比如现在我想在Introduction内写一部分literature review和industrial relevance,我可以把代码写成这样:

\begin{document}

\maketitle

\section{Introduction}
\subsection{Literature review}
This is my literature review.
\subsection{Indutrial relevance}
This is my industrial relevance.

\end{document}

再点击recompile,我们会发现文章内容变成了:
这里写图片描述
这时我们发下subsection会生成在当前的section之下并自动编号。有时候我们不想要这个编号,这时只需要在section后加*,写成\section*{}即可。
section将文章分为了几个部分,类似的还有\chapter{}指令,运用他可以强制文章从新的页面开始。

插入图片

想在LaTeX中插入图片,首先我们得引入一个叫package(包)的概念,就比如我需要修水管,那我就需要一个工具包。现在我想插入图片,我就在代码部分最顶层写\usepackage{graphicx}。
写文章的时候我们经常需要将图片加在文章当中,用word时我们只需要挪动想要的图片到文章的指定位置即可。但在LaTeX里我们这样加入图片,首先,在你想加入图片的位置打\begin{figure},这时你会发现有蓝色的一行文字代码自动出现,点击它,会自动出现一段代码:

\begin{figure}
    \centering
    \includegraphics{}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}

这里我想加入这样一张图片在文章里:
这里写图片描述
该图片在电脑里的文件名为ruocheng.png,要想插入到文章当中首先我们需要把这张图片上传到我们的文章项目中去。点击左上角的这个图标:
这里写图片描述
将我们需要的图片upload进去之后,我们可以看到在main之下已经出现了我们的图片的索引,现在我们可以开始着手修改代码了,首先在\begin{figure}后加上[H],这样做的目的是让图片不乱飘而是让他在写这段代码的地方出现,否则的话这张图片会在文章内很多奇怪的地方出现,但是要运用这个功能我们还要在代码开头添加一个包\usepackage{float}。紧接着,我们在\includegraphics后的大括号里面写入图片名变成\includegraphics{ruocheng.jpeg},这里一定要带上图片格式。然后我们开始设置图片的大小,在\includegraphics后加入中括号[],变成\includegraphics[width=3cm,height=3cm]{ruocheng.jepg}。下一行代码caption内我们所需要写的是图片的名字,这里我在括号内填充Astir让这行代码变成\caption{Astir}。接下来一行,同样是设定图片名字,只是这个图片名字并不是图片本身的名字,而是我们想要引用他是所用的名字(听起来是很绕口…)举个例子吧,写文章的时候我们经常需要写“Figure XXX shows that blablabla”, 这里的XXX是图片在文章里的编号,那如果我在文章里加了太多的图片,我如果对其中一个进行改动,之后的图片序号都会受到影响,只改一个还好,要是混乱的改几个,我们就要浪费很多时间改变出现在文章中的图片序号。而用LaTeX就剩了很多麻烦。在这里我们设定图片的引用名为ruocheng, 所以讲代码改为\label{ruocheng}。
那么现在整块图片代码就变成了:

\begin{figure}[H]
    \centering
    \includegraphics[width=3cm,height=3cm]{ruocheng.jpeg}
    \caption{Astir}
    \label{ruocheng}
\end{figure}

我们再在之前的section中加入这样一段话“As shown in Figure \ref{ruocheng, this man feels released at this moment.”

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}

\title{First project}
\author{750763559 }
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}
\subsection{Literature review}
This is my literature review.
\subsection{Indutrial relevance}
As shown in Figure \ref{ruocheng}, this man feels released at this moment.
\begin{figure}[H]
    \centering
    \includegraphics[width=3cm,height=3cm]{ruocheng.png}
    \caption{Astir}
    \label{ruocheng}
\end{figure}

\end{document}

经过编译之后,文章现在变成了这个样子:
这里写图片描述
这里我们发现,代码里的\ref{ruocheng直接变成了图片的编号,这个功能意味着我们可以按图来索引而不是记着图片序号来索引,又省了很多事。

插入reference

LaTeX相当方便的就是对reference的引用,这里我们用Harvard style作为例子。首先我们需要引入包\usepackage{harvard},在代码片段的开头加入它。之后我们点击左上角的按钮添加一个文件:
这里写图片描述
然后给文件命名为mylib.bib,在这里我们就创造了一个属于我们文章的文献库了。接着我们去找文献,目前无论是google学术还是其他的学术搜索引擎都会为我们直接提供bibText格式的代码,我们首先要做的就是把bibText的那一堆代码复制粘贴到刚刚创建的mylib之中去。这里我用百度学术搜索(今天翻墙不给力)。我查找到了如下的ref:
这里写图片描述
把鼠标放到“引用”这个位置:
这里写图片描述
点击之后,再点击左下角的倒入链接bibTex:
这里写图片描述
这时会自动跳出新网页页面:
这里写图片描述
将这段代码复制粘贴入我们刚创建的mylib.bib之中。然后我们在原文章代码的最底部写上以下代码:

\bibliographystyle{agsm} %其他选项包括dcu
\bibliography{mylib}

这时我们在原文章中写上我们需要引用文献的语句:“According to the research from \cite{Adam2008Sustainable}, urban planing and design is cool!” 代码如下:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\usepackage{harvard}


\title{First project}
\author{750763559 }
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}
\subsection{Literature review}
This is my literature review.
\subsection{Indutrial relevance}
As shown in Figure \ref{ruocheng}, this man feels released 
at this moment.
\begin{figure}[H]
    \centering
    \includegraphics[width=3cm,height=3cm]{ruocheng.png}
    \caption{Astir}
    \label{ruocheng}
\end{figure}
\noindent
According to the research from \cite{Adam2008Sustainable}, 
urban planing and design is cool!

\bibliographystyle{agsm} %其他选项包括dcu
\bibliography{mylib}





\end{document}

编译之后右半边页面输出的文章样式变成了:
这里写图片描述
接下来我们插入第二个reference,用相同的操作获得刚刚找到的第二个链接的bibTex格式的代码,复制它到mylib.bib之中,现在我们的mylib.bib文献库变成了这个样子:
这里写图片描述
这时我们再点回main.tex,写入我们要引用该文献的句子:“Only because of the research from \cite{Nasar1994Urban} that I finally understand the beauty of havard style!”。这时我们的maintext里的代码变成了:

\title{First project}
\author{750763559 }
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}
\subsection{Literature review}
This is my literature review.
\subsection{Indutrial relevance}
As shown in Figure \ref{ruocheng}, this man feels released 
at this moment.
\begin{figure}[H]
    \centering
    \includegraphics[width=3cm,height=3cm]{ruocheng.png}
    \caption{Astir}
    \label{ruocheng}
\end{figure}
\noindent
According to the research from \cite{Adam2008Sustainable}, 
urban planing and design is cool! Only because of the research 
from \cite{Nasar1994Urban} that I finally understand the 
beauty of havard style!

\bibliographystyle{agsm} %其他选项包括dcu
\bibliography{mylib}





\end{document}

经过编译之后文章变成了:
这里写图片描述
LaTeX的自动排版是不是非常方便。
现在我们总结一下插入reference(以havard style为标准)的步骤:
1.首先在代码里加入\usepackage{havard}
2.在文章末端插入两行代码用来显示我们已经引用的references。
3.创建一个新的文件格式为bib,命名为mylib.bib(当然你也可以用别的名字)。
4.在学术网站上找到bibTex格式的代码,复制粘贴它到mylib之中。
5.在原文中想要引用时,写上代码\cite{}, 大括号里面要写上你想要加的reference在我们文献库中的第一行标题,系统可以通过这个自动索引到我们要找到reference。
现在我们已经明白最基础的LaTeX知识,可以上手尝试写文章了!

猜你喜欢

转载自blog.csdn.net/BackroomFish/article/details/81434188