【LaTex】学习笔记:入门使用方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WeiDelight/article/details/48916101

     本博客的LaTex学习以MiKTex+TeXStudio为编辑器。

     关于LaTex环境的搭建和相关软件的安装,我主要是用了以下软件:

proTeXthttp://tug.org/protext/

MiKTexhttp://www.miktex.org/

TeXStudiohttp://texstudio.sf.net/

接下来介绍下入门的使用方法:

1、新建一个文件并编译

   打开TexStudio,新建tex文件,开始使用LaTex之旅。(选择 File -> New 即可)

   将以下代码复制粘贴到新建的文件中,编译即可(在菜单栏中选择Tools-> Compile,也可以选择“Build & View”,即可在右边看到编辑之后生成的pdf文件的效果了)。

\documentclass{article} 
\begin{document} 
  Hello, world!
\end{document}
   其中,\documentclass{}大括号里的“article”就是模板,在一篇文章中,我们定义了section和paragraph,但是具体的字体和字号没有被定义,而这些就可以在模板中实现。


2、设置标题、作者、时间等

扫描二维码关注公众号,回复: 4709312 查看本文章

   在一篇文章中,我们有时候会注明文章的标题,作者以及创建文章的时间,所以就需要在tex文件中进行添加。

\documentclass{article} 
  \title{My First LaTex} 
  \author{name} 
  \date{\today} 
\begin{document} 
  \maketitle   
  Hello, world!  
\end{document}
    其中,\maketitle将上面三行信息嵌入到文章中了,如果没有这句代码,那么生成的pdf文档只显示“Hello,world!”。


3、添加目录、设置章节和段落

\documentclass{article} 
\title{Hello World} 
\begin{document} 
	\maketitle 
	\tableofcontents
	\section{Hello 1} The first section. 
	  \subsection{Hello 11} The first subsection. 
	     \subsubsection{Hello 111} 
	        \paragraph{paragraphe}This is the paragraph. 
	            \subparagraph{subparagraph} This is the subparagraph.
	  \subsection{Hello 12} 
	      \paragraph{paragraph} This is the paragraph. 
\end{document} 
      其中,\tableofcontents 表示生成目录,“\tableofcontents ”和“\maketitle”的顺序不能颠倒,不然就会出现先有目录,下一页才是标题。“\section”和“\paragraph”这些是文章中的章节和段落的标志。


4、插入数学公式

   LaTex中插入数学公式有两种方式:

  (1)$...$可以开启行内数学模式,用于和文本合在一起使用。
  (2)“$$...$$”和“\[...\]”是另起一行居中开启数学模式。通常用起来差别不是很大,不过$$会修改默认的公式行间距,有时可能会对文章的整体效果有影响。

   同时还有引入包“amsmath”和“amssymb”,在文件开头“\documentclass{article}”下面插入以下两句话

\usepackage{amsmath} 
\usepackage{amssymb}
   其他一些相关的数学符号

   上标:E=mc^2 (E=mc2)

   下标:a_2    (a2)

   根式:\sqrt{·}

   分式:\frac{·}{·}(第一个参数为分子,第二个为分母)

   连加、连乘、极限、积分等大型运算符分别用\sum, \prod, \lim, \int生成。

   省略号:\dots, \cdots, \vdots, \ddots


5、插入图片和表格

   在LaTex中插入图片需要引入包graphicx,同时图片的路径需要跟tex文件所在的路径是一样的,运用\includegraphics命令设置插入图片的格式。

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

   插入表格
\documentclass{article} 
\begin{document} 
  \begin{tabular}{|c|l|} 
    1   &  2  \\ 
    33 &  4  \\ 
  \end{tabular} 

    
  \begin{tabular}{cl} 
   	1 & 2 \\ 
   	333 & 4\\ 
   \end{tabular} 
    
  \begin{tabular}{|l|r|} 
    \hline 
    111 & 2\\ 
    \hline 
    3 & 44 \\ 
    \hline 
  \end{tabular} 

  \begin{center} 
    \begin{tabular}{|c|c|} 
      \hline 
      1  &  2  \\ \hline 
      3 &  4 \\ 
      \hline 
    \end{tabular} 
  \end{center} 
\end{document} 
   其中,\hline表示横线,|表示竖线;用&来分列,用\\来强制换行;每列可以采用居左(l)、居中(|)、居右(r)等横向对齐方式。


猜你喜欢

转载自blog.csdn.net/WeiDelight/article/details/48916101
今日推荐