0%

LaTeX入门

LaTeX入门

什么是LaTeX

  • LaTeX是一种排版系统,它非常适用于生成高印刷质量的科技和数学类文档。这个系统同样适用于生成从简单信件到完整书籍的所有其他种类的文档。
  • 利用编写程序代码的方式写作
  • 目前比较方便的windows下的使用环境是TeXLive+vscode,安装方法百度。
  • 可以先用Markdown写点内容试试,两种语言的基本逻辑差不多,Markdown更轻量,网络博客中的文章基本都是用这个语法写成的。

为什么使用LaTeX

  • 在写作SCI论文时,杂志社有可能不会提供word格式的模版,但一定会有LaTeX的模版。
  • LaTeX排版整洁,不会像word那样发生不可预料的变化
  • 当在不同杂志社的模版之间切换时LaTeX更简洁、简单,因为代码是通用的。
  • 使用LaTeX写作科技论文时可以生成比较复杂的数学公式(现在word也可以办到)。
  • 使用LaTeX写作可能会在评审时给论文加分。

怎么使用LaTeX

文章基本结构

1
2
3
4
5
\documentclass{article} %除了article之外还有book、report、beamer

\begin{document}
Hello world!
\end{document}

如果要输入中文

1
2
3
4
5
\documentclass[UTF8]{ctexart} %ctex+article

\begin{document}
你好!
\end{document}
  • 所有位于\begin{document}之前的内容是前言,在这里制定文档页面大小、尺寸、也可以指定需要倒入的宏包
  • begin和end之间的才是正文,这里的内容会被排版生成到文档中

例如要给文章设置标题:

1
2
3
4
5
6
7
8
9
10
\documentclass[UTF8]{ctexart}

\title{你好,world!}
\author{张尔康}
\date{\today}

\begin{document}
\maketitle
你好,world!
\end{document}

文章的章节

LaTeX的章节生成十分的方便

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass[UTF8]{article}

\begin{document}

\section{Introduction} %第一章
Microneedles is a .......

\section{Methods} %第二章
\subsection{Fabrication of microneedles}
\subsubsection{Fabrication of the molds of microneedles}

\section{Results} %第三章

\end{document}

文章中字体的调节

1
2
3
4
5
6
7
8
9
10
11
\documentclass[UTF8]{ctexart}

\begin{document}
\textbf{hi},我是张尔康 %加粗,boldfont


\textit{hi},我是张尔康 %斜体,italic


\underline{hi},我是张尔康 %下划线
\end{document}

插入图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
\documentclass[UTF8]{ctexart}

\usepackage{hyperref}
\hypersetup{hypertex=true,
colorlinks=true,
linkcolor=blue,
anchorcolor=blue,
citecolor=blue}
\usepackage{graphicx}

\begin{document}

下面我将插入一张图片(Figure \ref{Figure 1})

\begin{figure}[htb] %开始图片环境
\centering %居中
\includegraphics[width=0.5\textwidth]{Jupiter} %图片大小及图片名字,要使用png格式
\caption{Jupiter is a ......} %图题
\label{Figure 1} %引用的名字
\end{figure} %结束图片环境

\end{document}

插入表格、列表

  • 无序列表
1
2
3
4
5
6
7
8
9
10
11
\documentclass[UTF8]{ctexart}

\begin{document}

\begin{itemize}
\item 第一点
\item 第二点
\item 第三点
\end{itemize}

\end{document}
  • 数字列表
1
2
3
4
5
6
7
8
9
10
11
\documentclass[UTF8]{ctexart}

\begin{document}

\begin{enumerate}
\item 第一点
\item 第二点
\item 第三点
\end{enumerate}

\end{document}
  • 表格
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
\documentclass[UTF8]{ctexart}

\begin{document}

\begin{tabular}{c c c} %三列,居中。l左对齐,r右对齐
过敏组 & 对照组 & 治疗组 \\
单元格 & 单元格 & 单元格 \\ %行之间用\\隔开
单元格 & 单元格 & 单元格
\end{tabular}

\begin{tabular}{ |c|c|c| } %用竖线加表格边框,也可以|c||c|双边框
\hline %\hline加上边框,也可以再加一个\hline添加双横线
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
\end{tabular}

\begin{tabular}{ |p{2cm}|c|c| } %paragraph,手动设置列宽
\hline
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
\end{tabular}

\begin{table}[htb]
\center %居中
\begin{tabular}{ |p{2cm}|c|c| }
\hline
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
单元格 & 单元格 & 单元格 \\
\hline
\end{tabular}
\caption{体重表} %添加表题
\end{table}

\end{document}

插入公式

  • 这个功能可能有的时候没有word方便
1
2
3
4
5
6
7
8
9
10
11
\documentclass[UTF8]{ctexart}

\begin{document}

爱因斯坦的质能方程:$E=mc^2$ %行内公式

\begin{equation}
E=mc^2
\end{equation} %行间公式

\end{document}
  • 复杂一点的公式
1
2
3
4
5
6
7
8
9
\documentclass[UTF8]{ctexart}

\begin{document}

\begin{equation}
d={k \varphi(n)+1} \over e
\end{equation}

\end{document}

插入参考文献

  • LaTex参考文献的插入和endnote等软件不一样
  • 下载文献时点击bibtex,网页会显示出以下内容:
1
2
3
4
5
6
7
8
9
10
@article{jones2017epicutaneous,
title={Epicutaneous immunotherapy for the treatment of peanut allergy in children and young adults},
author={Jones, Stacie M and Sicherer, Scott H and Burks, A Wesley and Leung, Donald YM and Lindblad, Robert W and Dawson, Peter and Henning, Alice K and Berin, M Cecilia and Chiang, David and Vickery, Brian P and others},
journal={Journal of Allergy and Clinical Immunology},
volume={139},
number={4},
pages={1242--1252},
year={2017},
publisher={Elsevier}
}

​ 这就是Latex中的参考文献格式

  • 使用时,首先在Latex文件的文件夹下创建一个新的bib文件(可以用记事本打开),并把上面的引用信息复制进去。(也可以使用别的管理文献的工具将end文件转化为bibtex文件,endnote等软件均有此功能)
  • jones2017epicutaneous,就是引用文献的label,在文章中输入\cite{li1999murine}来引用