LaTeX 入门 - 语法

一、使用 LaTeX 优点

这里首先说明,并不是因为 Word 排版不好才使用 LaTeX。之所以 Word 排版不美观,很大一部分是因为上手太简单,很少有人在使用 Word 时会像学习 LaTeX 时一样逛论坛、看文档,结果排出难看的文档后怪工具不方便。这里只列一下 LaTeX 的优点,并无对 Word 的特意中伤(但从开源角度是可以喷的,这取决于个人的价值观念)。

  • 完全自定义,自主设计,比 Word 更专业的排版超文本标记语言;
  • 设计效率高,不需频繁操作鼠标;
  • 复用性强,利用已有模板可实现快速专业的论文排版;
  • 对数学公式的支持性更好,不会像 Word 跑版;
  • 可更加专注于文章内容本身;
  • 大部分期刊要求 LaTeX 版本;
  • 可进行注释,且不显示在 pdf 中;
  • 不会像 Word 一样崩掉,不会因版本问题跑版;
  • 方便代码插入,可插入热门语言代码;
  • 开源。

二、LaTeX 官方文档

  • LaTeX 官方文档
  • CTEX LaTeX 文档
  • Overleaf LaTeX 文档
  • OI Wiki 文档

三、LaTeX 常用语法总结

  1. Hello World !
\documentclass{article}%文章类型-article,book,letter等
\title{My first Latex document}%文章标题
\author{Suancaiyu1806}%作者姓名
\date{\today}%日期,"\today"表示今天
\begin{document}%文档正文开始
\maketitle%控制序列,将文字按预定格式打印 Hello world! \end{document}%文档正文结束

  1. 文章类型

\documentclass[options]{class} 指明文档的类型及格式。

 \documentclass[11pt,twoside,a4paper]{article}%[]中参数使用','隔开%11pt文章主体字体大小,默认10pt%twoside双边编排,奇偶页左右边距相反%a4paper文档长宽同A4纸%{}中指出文章类型,article为论文格式

文档类型

class 参数 文章类型
article 论文类型
book 书籍类型
letter 信件类型
slides 幻灯片
IEEEtran IEEE Transactions格式的文章
proc 诉讼、议程
minimal 主要调试用
report 较长的报告
memoir 可更改文档的输出类型,基于book
beamer 自我介绍、业务陈述

自定义选项

option 参数 含义
10pt,11pt,12pt 正文字体大小,默认10pt
a4paper, letterpaper… 纸张大小
fleqn 公式左对齐
leqno 公式编号置于公式左
titlepage, notitlepage 指定文章标题后是否启用新页面,默认情况下,article类不启动新页面,而report和book启动
onecolumn, twocolumn 指定此文件要以单列或双列进行排版
twoside, oneside 单、双边编排,奇偶页左右边距相同、相反。book 类默认双边编排
landscape 横向打印
openright, openany 仅在右侧页或下一页开始新章节,report 默认下一页开始,book 默认右侧页开始
draft 草稿模式
  1. 目录

\tableofcontents 添加在导言区,即可显示目录。目录要编译两遍以上才正常:第一遍在.aux 辅助文件中记录位置,第二遍根据辅助文件的内容输出目录。如果目录本身会影响后续内容的页码,那么还要编译第三遍。(因此将配置时的 "latex-workshop.latex.autoClean.run": "onBuilt", 注释掉)

 \documentclass{article}  \title{My first Latex document} \author{Suancaiyu1806} \date{\today} \begin{document} \maketitle \tableofcontents%目录添加在导言区Hello world! \end{document}
  1. 章节、段落
 %边距\usepackage{geometry}\geometry{a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm}%设置纸张及边距(之前设置过纸张这里可不设置)%缩进与行间距\usepackage{indentfirst}\indent \linespread{1}%行间距%章节\section{}%一级\subsection{}%二级 \subsubsection{}%三级\usepackage[section]{placeins}%这一个包可以避免图或表在浮动时跨过section\renewcommand\thesection{\chinese{section}、}%此句可设置一级章节标题为中文,如:一、一级%段落\paragraph{}%一级\subparagraph{}%二级 \subsubparagraph{}%三级%注脚\footnote{FootNote}%注脚%页眉页脚\pagestyle{type}%全部页\thispagestyle{type}%当前页%type: empty-无页眉页脚;%plain-没有页眉,页脚包含一个居中的页码;%headings-没有页脚,页眉包含章/节或者字节的名字和页码;%myheadings-没有页脚,页眉包含有页码\setcounter{page}{number}%手动设置页码编号

示例

 \documentclass{article}  \title{My first Latex document} \author{Suancaiyu1806} \date{\today} \begin{document} \maketitle \tableofcontents \newpage%创建新页面\section{Chapter 1} \subsection{Section 1} \paragraph{I have a dream that one day this nation will rise up and live out the true meaning of its creed: We hold these truths to be self-evident that all men are created equal.}\subsection{Section 2}\paragraph{I have a dream that one day on the red hills of Georgia the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood.}\section{Chapter 2} \subsection{Section 1} \paragraph{I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice.} \subsection{Section 2}\paragraph{I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. I have a dream today!}\end{document}

  1. 字体
\usepackage{fontspec}%使用fontspec包
\setmainfont{Times New Roman}%设置主字体
\setsansfont{DejaVu Sans}%无衬线字体
\setmonofont{Latin Modern Mono}%等宽字体
\setsansfont{[font.ttf]}%使用当前目录下的字体文件
%%字体大小
\tiny \scriptsize \footnotesize \small \normalsize \large \large \LARGE \huge \Huge\title{\heiti The First Demo}%标题使用 The First Demo
\author{\kaishu 酸菜鱼}%作者使用楷书
\paragraph{\kaishu 酸菜鱼}%段落使用楷书
\paragraph{\huge I have a dream!}%段落字号huge
  1. 数学公式
Einstein 's $E=mc^2$.   %行内公式
\[ E=mc^2. \]   %行间公式
$m^{n}$ %上标
$m_{n}$ %下标
\frac{m}{n} %分式,n分之m
\sqrt{} %开平方
\sqrt[m]{n} %n开m次方
\sum_{i=m}^{n}  %累计求和,从m到n求和
\prod_{i=m}^{n} %累计求积,从m到n求积
\int_{i=m}^{n}  %从m到n积分
\vec a  %a向量
\overrightarrow{AB} %A到B的向量
a+b+\cdots+z    %a+b+…+z
\underbrace{a+b+\cdots+z}_{26}  %a+b+…+z
\overline{m+n}  %m+n公式上面加上横杠
\underline{m+n} %m+n公式下面加上横杠%%一行几个公式
\begin{displaymath}
S_{n+1} = S_{n} + S_{n},
S_{n}=1=2^{n}
\end{displaymath}
%%对行间公式进行标号
\begin{equation}
...
\end{equation}

  1. 方程组
$$
\left\{
\begin{array}{c}
a_1x+b_1y+c_1z=d_1 \\
a_2x+b_2y+c_2z=d_2 \\
a_3x+b_3y+c_3z=d_3
\end{array}
\right.
$$

  1. 矩阵
\usepackage{amsmath}$ \begin{matrix} 1 & 2 \\ 3 & 4 \\ \end{matrix} $%默认无括号
$ \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} $%圆括号
$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} $%方括号
$ \begin{Bmatrix} 1 & 2 \\ 3 & 4 \\ \end{Bmatrix} $%花括号
$ \begin{vmatrix} 1 & 2 \\ 3 & 4 \\ \end{vmatrix} $%行列式
$ \begin{Vmatrix} 1 & 2 \\ 3 & 4 \\ \end{Vmatrix} $%双竖线


使用 \cdots ⋯ , \ddots ⋱ , \vdots ⋮ 来输入省略符号

$$\begin{pmatrix}1      & a_1    & a_1^2  & \cdots & a_1^n  \\1      & a_2    & a_2^2  & \cdots & a_2^n  \\\vdots & \vdots & \vdots & \ddots & \vdots \\1      & a_m    & a_m^2  & \cdots & a_m^n  \\\end{pmatrix}
$$
$$\left[\begin{array}{cc|c}%分列1 & 2 & 3 \\4 & 5 & 6\end{array}\right]
$$This is a line: $\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)$

  1. 表格
\usepackage{booktabs}%%三线表
\begin{table}[htbp]\centering\caption{\label{tab:test}示例表格}%题注\setlength{\tabcolsep}{2cm}{%设置表格宽度\begin{tabular}{rccl}%对齐方式右 中 中 左\toprulehead1 & head2 & head3 & head4 \\\midrule1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\\bottomrule\end{tabular}}
\end{table}

\usepackage{booktabs}\begin{table}[htbp]\centering\caption{\label{tab:test}示例表格}\begin{tabular}{|rccl|}%左右有框线\hlinehead1 & head2 & head3 & head4 \\\hline1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\\hline\end{tabular}
\end{table}

\usepackage{amsmath}$$
\begin{array}{c|lcr}%分列,对齐方式左 中 右
n & \text{左对齐} & \text{居中对齐} & \text{右对齐} \\
\hline
1 & 1 & 2 & 3 \\
2 & 4 & 5 & 6 \\
3 & 7 & 8 & 1+10i
\end{array}
$$

$$
% outer vertical array of arrays 外层垂直表格
\begin{array}{c}% inner horizontal array of arrays 内层水平表格\begin{array}{cc}% inner array of minimum values 内层"最小值"数组\begin{array}{c|cccc}\text{min} & 0 & 1 & 2 & 3\\\hline0 & 0 & 0 & 0 & 0\\1 & 0 & 1 & 1 & 1\\2 & 0 & 1 & 2 & 2\\3 & 0 & 1 & 2 & 3\end{array}&%同行间% inner array of maximum values 内层"最大值"数组\begin{array}{c|cccc}\text{max}&0&1&2&3\\\hline0 & 0 & 1 & 2 & 3\\1 & 1 & 1 & 2 & 3\\2 & 2 & 2 & 2 & 3\\3 & 3 & 3 & 3 & 3\end{array}\end{array}% 内层第一行表格组结束\\%换行% inner array of delta values 内层第二行Delta值数组\begin{array}{c|cccc}\Delta&0&1&2&3\\\hline0 & 0 & 1 & 2 & 3\\1 & 1 & 0 & 1 & 2\\2 & 2 & 1 & 0 & 1\\3 & 3 & 2 & 1 & 0\end{array}% 内层第二行表格组结束
\end{array}
$$

  1. 图片
 \usepackage{graphicx}%使用graphicx包\includegraphics[width=3cm]{images/img2.jpg}%引入图片并设置大小\caption{Suancaiyu 1806}%题注

  1. 参考文献
  %%引用参考文献\cite{ref1}%%插入参考文献\begin{thebibliography}{99}\bibitem{ref1}Suancaiyu. LaTeX 入门.CSDN,2020(05):0-1.\bibitem{ref2}Suancaiyu. LaTeX 入门.CSDN,2020(05):0-1.\bibitem{ref3}Suancaiyu. LaTeX 入门.CSDN,2020(05):0-1.\bibitem{ref4}Suancaiyu. LaTeX 入门.CSDN,2020(05):0-1.\end{thebibliography}


12. 代码块

 \usepackage{xcolor}%高亮\usepackage{listings}%代码块\lstset{}%添加代码格式配置,文末%附录%中有有关python代码的配置\begin{lstlisting}[language=langue]\end{lstlisting}

  1. 插入附录
 \usepackage{appendix}\begin{appendices}\section{Appendice 1}\subsection{Appendice}\section{Appendice 2}\subsection{Appendice}\end{appendices}


附录

%%本段是对代码块有关格式配置,可直接添加在文档开始前
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}  \lstset{ %  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}  basicstyle=\footnotesize,        % the size of the fonts that are used for the code  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace  breaklines=true,                 % sets automatic line breaking  captionpos=bl,                   % sets the caption-position to bottom  commentstyle=\color{mygreen},    % comment style  deletekeywords={...},            % if you want to delete keywords from the given language  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8  frame=single,                    % adds a frame around the code  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)  keywordstyle=\color{blue},       % keyword style  %language=Python,                % the language of the code  morekeywords={*,...},            % if you want to add more keywords to the set  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)  numbersep=5pt,                   % how far the line-numbers are from the code  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'  showstringspaces=false,          % underline spaces within strings only  showtabs=false,                  % show tabs within strings adding particular underscores  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered  stringstyle=\color{orange},      % string literal style  tabsize=2,                       % sets default tabsize to 2 spaces  %title=myPython.py               % show the filename of files included with \lstinputlisting; also try caption instead of title
}

LaTeX 入门-语法相关推荐

  1. Latex 入门笔记(2) 常用语法

    文章目录 0. 前言 1. LaTeX 文档总体结构 2. 字符相关 3. 文档元素 3.1 章节与目录 3.2 标题页 3.3 列表.引用.摘要.代码 3.4 表格 4. 排版格式 4.1 字体.字 ...

  2. 学术写作利器——LaTeX入门笔记整理(不定期更新,附加使用心得)

    LaTeX入门教程(上) 比Word更适合学术写作的编纂语言 Credit:讲座是敝系的几个技术宅办的,作者只负责记录和整理.后面的更新是个人心得. 写这篇日志的初衷是小圈子分享和个人心得记录,适合完 ...

  3. Latex入门教程用法笔记(结尾附完整示例)

    以下是我在Latex使用过程中用到的一些语法,可能不是很全面,但是足够我使用了.有说错的地方还请大家谅解,在评论区多多指正-下面分为几个部分说明(注意导入所需要的包!可参照文章末尾完整示例里的用法) ...

  4. 我的LaTeX入门--h

    LaTeX概览 摘自维基百科: LaTeX, 是一种基于TEX的排版系统,由美国电脑学家莱斯利·兰伯特在20世纪80年代初期开发,利用这种格式,即使用户没有排版和程序设计的知识也可以充分发挥由TEX所 ...

  5. [论文阅读] (01) 拿什么来拯救我的拖延症?初学者如何提升编程兴趣及LATEX入门详解

    又是在凌晨三点赶作业,又是在Deadline前去熬夜,一次次无眠,一次次抱怨.为什么三年前.两年前.一年前,甚至是昨天,我都下定决心"从现在开始读顶会论文",却又悄悄选择逃避:为什 ...

  6. LaTeX入门教程 Elseiver模板使用

    LaTeX入门教程 & Elseiver模板使用 背景     最近准备向Elseiver期刊投稿,而官网仅提供了LaTeX写作模板,虽然内心有一万个不愿意使用LaTex(是的-我不会用==) ...

  7. latex入门(转载)

    新手写论文,需要使用latex,转载大佬的教程学习一波 一.LaTeX简介 结合维基百科及LaTeX官网可知: LaTeX(/ˈlɑːtɛx/,常被读作/ˈlɑːtɛk/或/ˈleɪtɛk/) 是一种 ...

  8. LaTeX入门学习-WinEdt

    LaTeX入门学习-WinEdt 1.下载 Latex的衍生版本众多,中文环境中常用的时CTex.下载地址为 http://www.ctex.org/CTeXDownload Ctex套装中自带Lat ...

  9. 【LaTeX】LaTeX入门

    文章目录 简介 文章结构 基本要素 处理问题 添加文档标题 章节 创建标签 生成目录(TOC) 文字处理 中文字体支持 字体效果 彩色字体 字体大小 段落缩进 列表 注释和空格 特殊字符 表格 图表 ...

最新文章

  1. centos升级python_CentOS 升级Python3
  2. 第5篇:Flowable快速工作流脚手架Jsite_请假实战_部署流程和发起流程
  3. java web 分页_Java Web(十一) 分页功能的实现
  4. 中国AR镜片市场现状研究分析与发展前景预测报告(2022)
  5. layabox 节点查找
  6. indexOf的用法
  7. [网络安全学习篇3]:批处理、病毒、用户与组管理、破解系统密码(千峰网络安全视频笔记 3 day)
  8. java故事之致敬坚持梦想的人
  9. C语言/C++初学 问题
  10. 如何计算对数收益率和净值化转换
  11. 基于云原生的大数据产品前端实践 | 第七期图文直播文字回放
  12. 小程序-输入关键字搜索,关键字在搜索列表中高亮效果
  13. 浅谈Git原理和常用命令(学习笔记)
  14. Python:for循环语句
  15. 强制删除五笔字型输入法
  16. sql的sum函数(与group by,having子句混合使用)
  17. 国服雷霆服务器维护,魔兽世界怀旧服国服开启免费定向转服,五个新服务器名字全被嫌弃...
  18. 【HTTP】HTTP报文首部
  19. 豆瓣Top250电影爬虫
  20. 水仙花数JAVA代码实现

热门文章

  1. ai是个什么软件,和PS一样么
  2. 色温,色阶,色调,色调
  3. matlab-colormap-contourf函数
  4. 【 SAP消息号BS013】
  5. 酒店管理系统的E-R图和数据库模型图
  6. 斗罗大陆CSS_204687
  7. Chrome双开(同一个版本配置两个独立的浏览器,附图)
  8. 世界十大骨传导耳机排行榜、实测主流骨传导耳机推荐解析必看榜单
  9. 【老生谈算法】matlab实现高斯白噪声仿真算法源码——高斯白噪声
  10. INFINONE XC164单片机逆向记录(R1) 汽车动力系统ECU固件逆向工程初探