一篇实用的Latex的入门教程

LaTeX新人教程,一小时从完全陌生到基本入门

LaTeX新人教程,一小时从完全陌生到基本入门

by Nan

对于真心渴望迅速上手LaTeX的人,可以只看正文。

曾经在缝缝补补中变得长长的“前言”被我丢到了正文后面当“后记”。

后记部分可以跳过不看或只看粗体。

原本这个版本的流程内容是30分钟。

后来应小伙伴呼声,加入了图片引用、公式引用和参考文献内容。

因此如果要走完这个流程的话,大致需要一个小时。

=============================================

下面是教程正文。(正文最后应大家要求增添了附录)

注:文章里的代码我自己测试是可以直接复制进winedt编译成功的。但是有朋友反馈说编译不成功,检查后的结果大概是在人人 发帖的时候,人人 自己神奇的排版系统自主“智能”增添了一些换行符制表符类似物。因此如果直接复制编译不成功的时候,请尝试手打一遍。代码内容已经十分精简,相信手打起来也不会有太大压力。

哈哈这一部分当然不包含在标题的一小时里。

新人不必纠结软件问题,随便什么软件随便什么版本只要下载下来能编译出pdf来就可以,先下载了装上来试试再说。我推荐winedt也是方便我在介绍按钮样子的时候可以统一描述。在真正开始跑步之前没有必要纠结该买NIKE跑鞋还是ADI跑鞋,跑起来再说。不要瞻前顾后,just try it.

2.第一个文档
打开WinEdt,建立一个新文档,将以下内容复制进入文档中,保存,保存类型选择为UTF-8。

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

然后在WinEdt的工具栏中找到编译按钮(在垃圾桶和字母B中间),在下拉菜单中选择XeLaTeX,并点击编译。 (这里请注意一下我之前一直笔误写的XeTeX,给大家带来困扰深感歉意)
如果顺利的话,我们就可以顺利生成出第一个pdf文件,点击工具栏中的放大镜按钮就可以快速打开生成的pdf文件。

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

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

块注释也有专门的语句,不过更方便的方式是选中一块区域点鼠标右键,点comment

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}

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

我对之前手滑写出New York is the capital of America这类低级错误表示非常抱歉。

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” role=”presentation” style=”text-align: center; position: relative;”>F=ma

   The Newton’s second law is
   F=ma” role=”presentation” style=”text-align: center; position: relative;”>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的数学符 表或别人给的例子。

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

...” role=”presentation” style=”text-align: center; position: relative;”>......” role=”presentation” style=”text-align: center; position: relative;”>...是另起一行居中开启数学模式。通常用起来差别不是很大,不过$$会修改默认的公式行间距,有时可能会对文章的整体效果有影响。

但是我最推荐使用的是equation环境,在之后的第9节中介绍。

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 /mtext>” role=”presentation” style=”position: relative;”>/mtext>.
    begin{figure}[!htbp]
      centering
      includegraphics[width = .8textwidth]{image1.jpg}
      caption{example of one image} label{one-img}
    end{figure}

  Image together is shown in Figure /mtext>” role=”presentation” style=”position: relative;”>/mtext>.
  First sub-image is shown as Figure /mtext>” role=”presentation” style=”position: relative;”>/mtext>.
  In Figure /mtext>” role=”presentation” style=”position: relative;”>/mtext> the second sub-image is presented.
    begin{figure}[!htbp]
      centering
      subfloat[first sub-image]{
        includegraphics[width = .45textwidth]{image1.jpg}
        label{sub1}
      }
      qquad
      subfloat[second sub-image]{
        includegraphics[width = .45textwidth]{image2.jpg}
        label{sub2}
      }
      caption{combined image}label{img-together}
    end{figure}

  The result is shown in Equation /mtext>” role=”presentation” style=”position: relative;”>/mtext>:
    begin{equation}label{abcde}
      a+b+c+d+e=f
    end{equation}

end{document}

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

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年11月23日
下一篇 2015年11月23日

相关推荐