latex_学习

参考:

  • https://www.overleaf.com/learn/latex/Free_online_introduction_to_LaTeX_(part_3)
  • https://www.overleaf.com/learn/latex/Free_online_introduction_to_LaTeX_(part_2)
  • https://www.overleaf.com/learn/latex/Free_online_introduction_to_LaTeX_(part_1)

latex 最大的好处在于它将格式和内容部分分离,其中格式部分主要由command组成,形如\documentclass{}。而内容直接键入便可,学习Latex便是学习Latex中常见的command。

x.1 Part1 基础知识

x.1.1 backbone

一个最简单的Latex文档必须包含两个command,分别是\documentclass{}\begin{document} \end{document},它的backbone应该长如下样子:

\documentclass{article}
\begin{document}
Hello World! % your content goes here...
\end{document}

x.1.2 空格和空行

所有的空格和换行都会被压缩为一个空格和一个换行,但我们可以通过\quad \\ 来实现多个空格和换行;

Words are separated by one or more
spaces. 

Paragraphs             are separated by one or more blank lines. Paragraphs are separated by one or more blank lines. Paragraphs are separated by one or more blank lines.

在这里插入图片描述

Words are separated by one or more
spaces. \\ \\ \\ 

Paragraphs are \quad separated by one or more blank lines. Paragraphs are separated by one or more blank lines. Paragraphs are separated by one or more blank lines.

在这里插入图片描述

x.1.3 特殊符号和转义字符

有四种特殊字符如下:

% 注释
$ 数学公式
# 占位符
& 对齐
\ 用于构成command或者和上四组合形成转义字符
` me ' 前单引号和后单引号
`` me '' 前双引号和后双引号

有四种符号有特殊意思,但是可以前跟\实现转义字符的用处。\% \# \& \$

x.1.4 优美的数学公式

latex编辑优美的数学公式,如果是嵌入式数学公式使用$ equation $实现;如果是单行数学公式使用\begin{equation} euqation \end{equation}实现($$ $$是tex过时的方法且存在兼容性问题)。

latex还提供了很多种command用于优雅表达公式,例如\sum和希腊字母\omega等等。

We can write
$ \Omega = \sum_{k=1}^{n} \omega_k $
in text, or we can write
\begin{equation}
\Omega = \sum_{k=1}^{n} \omega_k
\end{equation}
to display it.

x.1.5 \begin{} \end{}创建environment 或者 用于创造列表

我们使用\begin{} \end{}来创建新的environment,例如我们可以创建列表的environment如下,

常见无序表和顺序表创建如下:

% 无序表
\begin{itemize} % for bullet points
\item Biscuits
\item Tea
\end{itemize}

% 有序表
\begin{enumerate} % for numbers
\item Biscuits
\item Tea
\end{enumerate}

x.1.6 用 \usepackage{} 导入第三方库

我们在 \documentclass{}\begin{document} 间插入第三方库,如下,

\documentclass{article}
\usepackage{amsmath} % preamble
\begin{document}
% now we can use commands from amsmath here...
\end{document}

x.1.7 overleaf使用vim编辑器

menu - keybindings - Vim 改为 Vim 编辑器。

在这里插入图片描述

在这里插入图片描述

x.2 Part2 结构; 图片/公式序号; 图片; 表格; 引用;

x.2.1 结构

包括主要标签\documentclass{}\begin{document} \end{document}\title{The Title};\author{A. Author};\date{\today} 和 \maketitle\begin{abstract} \end{abstract};\section{Introduction};\section{Method};\section{Results};\section{Conclusion}\subsection{Sample Preparation};\subsection{Data Collection}。总体使用结果如下:

\documentclass{article}

\title{The title}
\author{A. Author}
\date{\today}

\begin{document}
\maketitle

\begin{abstract}
This the abstract    
\end{abstract}

\section{Introduction}

\section{Method}

\subsection{Sample Preparation}

\subsection{Data Analysis}

\section{Result}

\section{Conclusion}

\end{document}

x.2.2 章节/公式/图片序号

使用\label\ref添加章节/图片序号的引用;使用\usepackage{amsmath}\label\eqref增加对公式序号的引用;详见如下,

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

能看到最终引用效果如下,

在这里插入图片描述

x.2.3 图片

图片使用 \usepackage{graphicx}\includegraphics[]{} 来增加对图片的引用;更加添加\begin{figure}\caption{}lable{}\ref{}形成对图片功能的引用;

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=0.5\linewidth]{1.png}
    \caption{Test for...}
    \label{fig:enter-label}
\end{figure}

\includegraphics[width=0.3\textwidth, angle=270]{1.png}

Figure \ref{fig:enter-label} shows that ...

\end{document}

在这里插入图片描述

x.2.4 表格

表格我们使用\begin{tabular}{lrr}来添加,增加 | 来指定竖直的线,增加 \hline 来指定水平的线;

\documentclass{article}

\begin{document}

\begin{tabular}{l | r} \hline
    people  & price     \\ \hline
    Joker   & 100       \\
    Crow    & 199       \\ \hline
\end{tabular}

\end{document}

在这里插入图片描述

x.2.5 引用

在增加引用的时候我们往往需要创建一个新文件.bib,我们需要使用的command包括\usepackage{natbib}\citet{} 和 \citep{} 两种不同的引用格式\bibliography{}指定.bib文件的名称,\bibliographystyle{plainnat}指定reference的格式类型;

其中.bib文件的组织格式如下,

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

在文中我们可以如下引用:

\documentclass{article}
\usepackage{natbib}

\begin{document}
\citet{Brooks1997Methodology} show that \ldots. Clearly, all odd numbers are prime \citep{Jacobson1999Towards}.

\bibliography{ref}

\bibliographystyle{plainnat} % try changing to abbrvnat

\end{document}

在这里插入图片描述

x.2.6 安装本地tex

使用Overleaf或者本地tex,

mac用户安装 MacTex + VSCode插件,安装步骤可见https://zhuanlan.zhihu.com/p/560361957

x.2.7 代码汇总

\documentclass{article}
\usepackage{amsmath}    % use \eqref
\usepackage{graphicx}   % use \includegraphics
\usepackage{natbib}     % use \citet

\title{The title}
\author{A. Author}
\date{\today}

\begin{document}
\maketitle

\begin{abstract}
This the abstract    
\end{abstract}

\section{Introduction}
\label{sec:intro}
This problem is about \ldots

We can see in Section in \ref{ss} and Equation in \eqref{eq:1}

\section{Method}
\label{ss}
We investigate \ldots

In Section \ref{sec:intro}  

\begin{equation}
    \label{eq:1}
    e^{i\pi} + 1 = 0
\end{equation}

\subsection{Sample Preparation}

\begin{figure}
    \centering
    \includegraphics[width=0.5\linewidth]{1.png}
    \caption{Test for...}
    \label{fig:enter-label}
\end{figure}

Figure \ref{fig:enter-label} shows that ...

\includegraphics[width=0.5\textwidth]{1.png}

\includegraphics[width=0.3\textwidth, angle=270]{1.png}

\subsection{Data Analysis}

\begin{tabular}{l | r} \hline
    people  & price     \\ \hline
    Joker   & 100       \\
    Crow    & 199       \\ \hline
\end{tabular}

\section{Result}

\section{Conclusion}

\citet{Brooks1997Methodology}
show that \ldots. Clearly,
all odd numbers are prime
\citep{Jacobson1999Towards}.    

\bibliography{ref}
% if `bib-example' is the name of
% your bib file

\bibliographystyle{abbrvnat}
% try changing to abbrvnat, plainnat

\end{document}

其中图片是一张名为1.png的图片,引用ref.bib如下,

@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}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值