从零开始用LaTeX

一、前言

第一次用LaTeX,记录一下笔记。

博主是从零开始的。大家不要害怕,跟着来。

先从模仿开始,掌握基础知识。

二、正文

1.LaTeX软件的安装和使用 

Windows系统下LaTeX版本:CTex,MITex,proTex,Tex Live。

我只知道CTex对中文会友好点,其它区别不清楚。对于小白的我,知道怎么用是第一步。

“黑猫白猫,能抓得到老鼠的都是好猫。”先知道基础知识,别想太多,我就在纠结用哪一个版本费了很多时间。

(1)CTex

官方网址:  下载中心:CTEX  http://www.ctex.org/CTeXDownload/

下载安装即可。

我下的是CTex。

安装后,打开这个即可

(2)LaTeX

官方网址:LaTeX - A document preparation system  https://www.latex-project.org/

第一步,点进去,选择“Get”

第二步,下拉。选择自己的版本,下载安装。

2.第一个文件


打开WinEdt,建立一个新文档,将以下内容复制进入文档中并去掉%,保存,保存类型选择为UTF-8。 编译并观察现象。 

复制后,点击图中红圈内容即可生成pdf

\documentclass{article} 
\begin{document} 
hello, world 
\end{document} 

结果如下图所示

3.标题、作者和注释 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察现象。 

\documentclass{article} 
  \author{My Name} 
  \title{The Title} 
\begin{document} 
  \maketitle 
  hello, world % This is comment 
\end{document}

%为本行右边所有内容被注释掉,在生成的pdf中不会显示。

4.章节和段落 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察现象。 

\documentclass{article} 
  \title{Hello World} 
\begin{document} 
  \maketitle 
  \section{Hello China} China is in East Asia. 
    \subsection{Hello Beijing} Beijing is the capital of China. 
      \subsubsection{Hello Dongcheng District} 
        \paragraph{Tian'anmen Square}is in the center of Beijing 
          \subparagraph{Chairman Mao} is in the center of Tian'anmen Square 
      \subsection{Hello Guangzhou} 
        \paragraph{Sun Yat-sen University} is the best university in Guangzhou. 
\end{document} 

退格只是个人偏好,看起来层次清晰美观。实际操作上未必要如此,每一行之前的空格不影响编译生成PDF的排版结果。 


5.加入目录 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察现象。 

\documentclass{article} 
\begin{document} 
  \tableofcontents 
  \section{Hello China} China is in East Asia. 
    \subsection{Hello Beijing} Beijing is the capital of China. 
      \subsubsection{Hello Dongcheng District} 
        \paragraph{Hello Tian'anmen Square}is in the center of Beijing 
          \subparagraph{Hello Chairman Mao} is in the center of Tian'anmen Square 
\end{document} 

6.换行 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察对比现象。 

\documentclass{article} 
\begin{document} 
  Beijing is 
  the capital 
  of China. 

  Washington is 

  the capital 

  of America. 

  Amsterdam is \\ the capital \\ 
  of the Netherlands. 
\end{document}

空一行为另起一段,\\为段内强制换行。

7.数学公式 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察对比现象。 

\documentclass{article} 
  \usepackage{amsmath} 
  \usepackage{amssymb} 
\begin{document} 
  The Newton's second law is F=ma. 

  The Newton's second law is $F=ma$. 

  The Newton's second law is 
  $$F=ma$$ 

  The Newton's second law is 
  \[F=ma\] 

  Greek Letters $\eta$ and $\mu$ 

  Fraction $\frac{a}{b}$ 

  Power $a^b$ 

  Subscript $a_b$ 

  Derivate $\frac{\partial y}{\partial t} $ 

  Vector $\vec{n}$ 

  Bold $\mathbf{n}$ 

  To time differential $\dot{F}$ 

  Matrix (lcr here means left, center or right for each column) 
  \[ 
    \left[ 
      \begin{array}{lcr} 
        a1 & b22 & c333 \\ 
        d444 & e555555 & f6 
      \end{array} 
    \right] 
  \] 

Equations(here \& is the symbol for aligning different rows) 
\begin{align} 
  a+b&=c\\ 
  d&=e+f+g 
\end{align} 

\[ 
  \left\{ 
    \begin{aligned} 
      &a+b=c\\ 
      &d=e+f+g 
    \end{aligned} 
  \right. 
\] 

\end{document} 

具体细节可以自行搜索LaTeX的数学符号表或别人给的例子。

$...$是开启行内数学模式,用于和文本合在一起使用。

$$...$$和\[...\]是另起一行居中开启数学模式。通常用起来差别不是很大,不过$$会修改默认的公式行间距,有时可能会对文章的整体效果有影响。但是我最推荐使用的是equation环境,在之后的第9节中介绍。

有一些网站可以通过画图的方式来生成公式,有的编辑器集成了各种数学功能按钮。这对于公式需求少的人来说很方便,具体信息可以自己去搜索。但是如果你的文章中要出现大段的证明过程,就会发觉还是老老实实地google一篇latex数学符号表,然后不懂的去查代码,自己用手指敲来得干脆利索。再进阶一点,可以去搜一下有关LaTeX的自定义command的内容去看一下,在敲公式时能省很多力气。


8.插入图片 


将待插入的图片姑且先命名为figure1.jpg 
建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,放在和图片文件同一个文件夹里,编译并观察现象。 

\documentclass{article} 
  \usepackage{graphicx} 
\begin{document} 
  \includegraphics[width=4.00in,height=3.00in]{figure1.jpg} 
\end{document}

现在LaTeX对jpg、bmp、png等等常见图片都可以支持。

9.可以被引用的图片和公式

 

接下来进阶一点,我们来做有图片名称,可以在文中被引用的插入图片,还有可以在文中被引用的公式。建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,放在和图片文件同一个文件夹里。编译方式可以选择XeLaTeX或PDFTeXify。如果选择XeLaTeX,那么需要编译两次。如果选择PDFTeXify,那么编译一次就可以。

\documentclass{article} 
\usepackage{amsmath} 
\usepackage{amssymb} 
\usepackage{graphicx, subfig} 
\usepackage{caption} 
\begin{document} 
  One image \ref{one-img}. 
    \begin{figure}[!htbp] 
      \centering 
      \includegraphics[width = .8\textwidth]{image1.jpg} 
      \caption{example of one image} \label{one-img} 
    \end{figure} 

  Image together is shown in Figure \ref{img-together}. 
  First sub-image is shown as Figure \ref{sub1}. 
  In Figure \ref{sub2} the second sub-image is presented. 
    \begin{figure}[!htbp] 
      \centering 
      \subfloat[first sub-image]{ 
        \includegraphics[width = .45\textwidth]{image1.jpg} 
        \label{sub1} 
      } 
      \qquad 
      \subfloat[second sub-image]{ 
        \includegraphics[width = .45\textwidth]{image2.jpg} 
        \label{sub2} 
      } 
      \caption{combined image}\label{img-together} 
    \end{figure} 

  The result is shown in Equation \ref{abcde}: 
    \begin{equation}\label{abcde} 
      a+b+c+d+e=f 
    \end{equation} 

\end{document} 

10.简单表格 


建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8,编译并观察对比现象。 

\documentclass{article}
\begin{document}
  \begin{tabular}{|c|c|}
    a & b \\
    c & d\\
  \end{tabular}

  \begin{tabular}{|c|c|}
    \hline
    a & b \\
    \hline
    c & d\\
    \hline
  \end{tabular}

  \begin{center}
    \begin{tabular}{|c|c|}
      \hline
      a & b \\ \hline
      c & d\\
      \hline
    \end{tabular}
  \end{center}
\end{document}

11.制作参考文献

建立一个新文档,把以下内容复制进入文档中,保存,保存文件名为references.bib,保存类型为UTF-8。这个文档专门用来存放参考文献的信息。

@article{rivero2001resistance,
title={Resistance to cold and heat stress: accumulation of phenolic compounds in tomato and watermelon plants},
author={Rivero, Rosa M and Ruiz, Juan M and Garc{\i}a, Pablo C and L{\'o}pez-Lefebre, Luis R and S{\'a}nchez, Esteban and Romero, Luis},
journal={Plant Science},
volume={160},
number={2},
pages={315--321},
year={2001},
publisher={Elsevier}
}

@article{gostout1992clinical,
title={The clinical and endoscopic spectrum of the watermelon stomach},
author={Gostout, Christopher J and Viggiano, Thomas R and Ahlquist, David A and Wang, Kenneth K and Larson, Mark V and Balm, Rita},
journal={Journal of clinical gastroenterology},
volume={15},
number={3},
pages={256--263},
year={1992},
publisher={LWW} 
}

建立一个新文档,把以下内容复制进入文档中,保存在同一个文件夹里,保存类型为UTF-8。编译并观察对比现象。 

\documentclass{article} 
\usepackage[numbers]{natbib} 
\begin{document} 
  One reference about watermelon \cite{gostout1992clinical} 
  Another reference about watermelon \cite{rivero2001resistance} 
  \bibliographystyle{plain} 
  \bibliography{references} 
\end{document}

参考

latex 入门_晓夜星晕0_新浪博客  http://blog.sina.com.cn/s/blog_eb957f6f0102vs58.html

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值