目录
概述
- 学习方法:1、看视频学习常用语法操作;2、根据需要直接用latex写论文文档,不懂的地方上网搜索解决;3、对于复杂论文排版可以查阅Latex书籍,那本不太简短的Latex介绍;
- 常用的Tex发行版本有两个:TexLive和MikTex;TexLive提供的包很全,但占用空间大;MikTex占用空间小,安装速度快,但遇到本地缺少的包需联网下载;(Overleaf是免费在线使用的Tex编辑器);
- TexLive安装完毕后,可打开其自带的编辑器TeXworks使用,也可选择自己喜欢的任意文本编辑器(比如VScode;vscode可以配置Latex );
基本语法
基本命令格式解释
- \命令名{ } ——LaTex所有命令都以\开头,{ }中内容代表这个命令的参数;
\documentclass[UTF8]{ctexart}
\title{倚天屠龙记}
\author{张无忌}
\data{\today}
\begin{document}
\maketitle
helloworld!
\end{document}
- documentclass指定的文档类型,最广泛使用的文档类型有article(代表普通文章),beamer(幻灯片格式文档),ctexart(简体中文和英文混排),book, report....
- 所有位于\begin{document}之前的内容都被称为前言(preamble),在这之前设置文档格式、页面尺寸、文档需导入的宏包等;
- [UTF8]指定文档的编码类型;UTF8是TeXworks编辑器默认使用的编码类型;
- 介于\begin{document}和\end{document}之间的内容称为文档的正文(body);在这片区域输入的内容都将被排版到最终生成的文档中;
- 在前言区通过\title{ }命令给文档设置一个标题;\author{ }命令指定作者的名字; \data{ }指定文档修改的日期, \data{ \today}命令自动生成当天日期;要显示这些信息需在正文区添加\maketitle命令,这个命令会在当前位置生成文档的标题,标题内容即是在前言区(preamble)设定的信息;
特殊符号
- 一般是以$...$的原则编写特殊符号;遇到不常见的,尝试使用 $\(中间放置不常见的符号)$
- ∃
$\exists$
- ∀
$\forall$
- ¬
$\neg$
- “_” 短线;如read_dimacs————read$\_$dimacs
$\_$
- 下划线 ;
\underline
举例:
love \underline{Emphasized} text and \underline{another} and \underline{other}
分页
- \newpage
- 举例:标题自成一页,正文从下一页开始
字体设置
- \textbf{ }——设置粗体bf(bold font),需加粗的内容可直接写在花括号中;\textit{ }——设置斜体it(italic),\underline{ }——设置下划线标记文字;回车换行符——输入一个换行符表示生成一个空格,连续健入两个换行符表示新起一个段落;空格命令:\quad 表示大概1.5个英文字母宽度的空格,\qquad 表示大概3个英文字母宽度的空格;
-
两个quad空格 a \qquad b quad空格 a \quad b 大空格 a\ b 中等空格 a\;b 小空格 a\,b 没有空格 ab 紧贴 a\!b
\documentclass[UTF8]{ctexart}
\title{倚天屠龙记}
\author{张无忌}
\date{\today}
\begin{document}
\maketitle
\textbf{与非图(And Inverter Graph, AIG)}是一种表示数字逻辑电路的特殊 DAG。AIG 中每一个节点都只有两个输入,用来表示“与”门,利用带有黑点的有向边表示反相器,\textit{即AIG 是由两输入的“与”门、反相器和有向边组成。} AIG 因每个节点均表示二输入的与门,因此是一种\underline{同构 (homogeneous)} 逻辑网络。
其优点在于同构网络在执行逻辑变换过程中速度快,即使面向工业级电路综合亦可有优异的性能。
\end{document}
章节设置
- \section{ }——开启一个新章节,{ }中内容代表章节的名字;\subsection{ }——在当前章节下创建一个子章节或二级章节;\subsubsection{ }——创建3级章节;\chapter{ }——比section更大; 可表示书籍中章节;\part{ }——比chapter更大;可用于表示书籍中第几部分;如果你想取消某个章节的编号,简单地在命令的大括号前加一个星号(*)即可,如:\section*{参考文献}
- 有关章节设置参考:LaTeX 章节 Sections Chapters_Xovee的博客-CSDN博客_latex 章节
\documentclass[UTF8]{ctexbook}
\title{倚天屠龙记}
\author{张无忌}
\date{\today}
\begin{document}
\maketitle
\chapter{基本概念}
\section{第一章AIG} 与非图(And Inverter Graph, AIG)是一种表示数字逻辑电路的特殊 DAG。AIG 中每一个节点都只有两个输入,用来表示“与”门,利用带有黑点的有向边表示反相器,即AIG 是由两输入的“与”门、反相器和有向边组成。
\subsection{反相器} AIG 因每个节点均表示二输入的与门,因此是一种同构 (homogeneous) 逻辑网络,其优点在于同构网络在执行逻辑变换过程中速度快,即使面向工业级电路综合亦可有优异的性能。
\section{第二章MIG}多数反相器图(Majority-Inverter Graph, MIG)是近年来一种用于逻辑综合和优化数据结构。\subsection{Majority}它是由三输入的多数(Majority)门和反相器组成的逻辑网表。与 AIG 类似,它也是有向无环图的一种,但是 MIG 和 AIG 的区别是前者图中含有 Majority 门(MAJ)结点。
\section{第三章蕴含}文本蕴含(指文本和假设之间的一种广义关系)——文本H 和假设T语义上具有如下关系:若H的含义能够从文本T中推理出来,则称T蕴含H。(即若有T→H,则称T蕴含H)。
\end{document}
图片
- 要在文档中添加图片,需先在前言区引用\usepackage{graphicx}这个包,包中包含若干绘制图片的指令;在正文中可以使用\includegraphics{ }命令在当前位置添加一张图片{ }中填写图片文件的名字,在名字中可直接省略掉后面png的扩展名部分;(注意将图片防到当前.tex文件同级目录下);
- [width=0.5textwidth],其中\textwidth表示当前文本区域宽度,用此参数对图片尺寸做调整;
- 为图片添加标题,先将图片嵌套至figure环境中,使用命令\begin{figure}和\end{figure},再用\caption{ }命令指定图片标题,使用\centering命令使图片居中显示;
- \begin{figure}[htbp]添加[htbp]使得图片显示保持在文字当前页,不添加[htbp]图片会跑到下一页;htbp表latex会尽量满足排在前面的浮动格式,就是h-t-b-p这个顺序,让排版的效果尽量好;h:here,表示在此处;t:top,表示在顶部;b:bottom,表示底部;p:page,表示在本页;在前言区添加\usepackage{stfloats}再添加htbp,图片就会保持=在本页了;
- 修改图片参数[htbp]为[H]可强制图片固定在当前位置,不受页面及文字影响,也可改为[T]固定图片位置;(%是latex注释符)
\begin{figure}[H] %强制固定图片在当前位置
\centering
\includegraphics[width=0.8\textwidth]{图1}
\caption{LEC算法流程框图}
\end{figure}
\documentclass[UTF8]{ctexbook}
\usepackage{stfloats}
\usepackage{graphicx}
\begin{document}
\chapter{基本概念}
\section{第一章AIG} 与非图(And Inverter Graph, AIG)是一种表示数字逻辑电路的特殊 DAG。\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{AIG}
\caption{c17电路AIG图}
\end{figure}
\end{document}
列表
- 要在Latex中显示列表需先切换到列表的“环境”中,environment类似与c++中的作用域,任何介于\begin{ }和\end{ }之间的内容都属于同一环境,位于同一环境中的内容将会共享相同的文字格式;
- 对于无序列表的创建,可以使用itemize环境,列表中的每个元素都需以\item开头;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{itemize}
\item 列表项1
\item 列表项2
\item 列表项3
\end{itemize}
\end{document}
- 对于有序列表创建,使用enumerate环境,列表中元素以\item开头;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{enumerate}
\item 列表项A
\item 列表项B
\item 列表项C
\end{enumerate}
\end{document}
数学公式
- 行内公式(inline equation),Latex允许在段落内直接添加公式,行内公式需要写在$...$之间;
- 将公式独立显示在一行,需使用equation环境,也可将equation环境环境简写为:以\[ 开始 \]结尾的形式;
\documentclass[UTF8]{ctexart}
\begin{document}
爱因斯坦在1995年发现的质量守恒公式为: $E=mc^2$
重力加速度公式如下:
\begin{equation}
g=GM/r^2
\end{equation}
开普勒第三定律:
\[
a^3/T^2=k
\]
\end{document}
- 对于复杂公式,需熟记公式中常用的一些指令;如RSA公式:\over表示几分之几,分子在前,分母在后;下列公式中分子是另一表达式,因此将表达式用{ }括起来,其中{ }不会显示在最终公式中;\varphi表示小写的符号,\phi表示;
- latex中公式加粗显示:LaTeX中数学 公式 希腊字母符号 加粗的方法 - 简书
- 在线Latex公式查询测试编辑器codecogs,可以快速测试想要排版的公式;快速查询公式语法;Online LaTeX Equation Editor - create, integrate and download online.
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{equation}
d={k\varphi(n)+1}\over e
\end{equation}
\end{document}
常用公式命令:
- 下标
C_{init}
- 上下标
L_{*}^{(T)}
- 左右括号( )
\left (L_{init}, C_{init} \right)
- 左右花括号{ }
\left\{abc\right\}
- 输入百分号%
50\%
- 幂次方
2\times 10^{-5}
表格
- 可以使用tabular环境在当前位置创建一个表格,tabular环境要求我们传入一个参数用来指定表格的尺寸,{c c c}代表表格一共有3列,其中每列内容居中对齐c=centering;
- 替换c为l表示左对齐,r代表右对齐;
- \begin{tabular}和\end{tabular}区域定义表格中需要显示内容;每列数据用&符号隔开,每行数据以\\分割;
- 加入竖线|为表格添加竖直的边框;\hline命令添加水平边框;可输入\hline\hline添加双横线效果;
- 设置列宽, 将c改为p并在其后{ }中输入列宽,p=paragraph是一种允许设置列宽的列格式;
- 为表格添加标题:先将整个表格放在一个table环境,通过\caption{ }命令指定表格的标题,并通过\center命令将表格居中显示;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{tabular}{c c c}
姓名 & 年龄 & 性别 \\
小明 & 8 & 男 \\
小红 & 12 & 女 \\
\end{tabular}
\end{document}
加入竖线|为表格添加竖直的边框;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{tabular}{|c| c |c|}
姓名 & 年龄 & 性别 \\
小明 & 8 & 男 \\
小红 & 12 & 女 \\
\end{tabular}
\end{document}
\hline命令添加水平边框;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{tabular}{|c| c |c|}
\hline
姓名 & 年龄 & 性别 \\
\hline
小明 & 8 & 男 \\
\hline
小红 & 12 & 女 \\
\hline
\end{tabular}
\end{document}
设置列宽;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{tabular}{|p{2cm}| c |c|}
\hline
姓名 & 年龄 & 性别 \\
\hline\hline
小明 & 8 & 男 \\
\hline
小红 & 12 & 女 \\
\hline
\end{tabular}
\end{document}
为表格添加标题;
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{table}
\center
\begin{tabular}{|p{1cm}| c |c|}
\hline
姓名 & 年龄 & 性别 \\
\hline
小明 & 8 & 男 \\
\hline
小红 & 12 & 女 \\
\hline
\end{tabular}
\caption{学生信息}
\end{table}
\end{document}
让表格中文字居中显示;<{\centering}命令为居中; 需要添加包:\usepackage{array}
例如:
\begin{table}[htbp]
\centering
\caption{AND门故障真值表}
\begin{tabular}{|p{4em}|c|c|c|c|c|c|c|}
\hline
输入 & \multicolumn{1}{p{5.375em}|}{无故障输出} & \multicolumn{6}{p{23.5em}|}{SSF故障输出} \\
\hline
a b & \multicolumn{1}{p{5.375em}|}{c} & \multicolumn{1}{p{3.75em}|}{a-SA0} & \multicolumn{1}{p{3.75em}|}{a-SA1} & \multicolumn{1}{p{4em}|}{b-SA0} & \multicolumn{1}{p{4em}|}{b-SA1} & \multicolumn{1}{p{4em}|}{c-SA0} & \multicolumn{1}{p{4em}|}{c-SA1} \\
\hline
0 0 & 0 & 0 & 0 & 0 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
0 1 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} & 0 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
1 0 & 0 & 0 & 1 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
1 1 & 1 & \textcolor[rgb]{ 1, 0, 0}{0} & 0 & \textcolor[rgb]{ 1, 0, 0}{0} & 1 & \textcolor[rgb]{ 1, 0, 0}{0} & 1 \\
\hline
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
上述代码表格显示为:
加入命令<{\centering}使得表格中文字居中显示;如:针对表格中"SFF故障输出",修改命令为:\multicolumn{6}{p{23.5em}<{\centering}|}{SSF故障输出}
修改上述表格代码为:
\begin{table}[htbp]
\centering
\caption{AND门故障真值表}
\begin{tabular}{|p{4em}|c|c|c|c|c|c|c|}
\hline
\quad 输入 & \multicolumn{1}{p{5.375em}<{\centering}|}{无故障输出} & \multicolumn{6}{p{23.5em}<{\centering}|}{SSF故障输出} \\
\hline
\quad a b & \multicolumn{1}{p{5.375em}<{\centering}|}{c} & \multicolumn{1}{p{3.75em}|}{a-SA0} & \multicolumn{1}{p{3.75em}|}{a-SA1} & \multicolumn{1}{p{4em}|}{b-SA0} & \multicolumn{1}{p{4em}|}{b-SA1} & \multicolumn{1}{p{4em}|}{c-SA0} & \multicolumn{1}{p{4em}|}{c-SA1} \\
\hline
\quad 0 0 & 0 & 0 & 0 & 0 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
\quad 0 1 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} & 0 & 0 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
\quad 1 0 & 0 & 0 & 1 & 0 & \textcolor[rgb]{ 1, 0, 0}{1} & 0 & \textcolor[rgb]{ 1, 0, 0}{1} \\
\hline
\quad 1 1 & 1 & \textcolor[rgb]{ 1, 0, 0}{0} & 0 & \textcolor[rgb]{ 1, 0, 0}{0} & 1 & \textcolor[rgb]{ 1, 0, 0}{0} & 1 \\
\hline
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
运行代码,表格显示为:
特殊符号
- latex中波浪号~;
方式1:一般文字环境下,\textasciitilde
方式2:公式环境下,$ \sim $区别:用公式环境下打出,会大一些!
去掉日期和作者信息显示(不留空行)
在序言区插入下列代码,通过改变内部的\@maketitle变量来重新定义\maketitle行为;
% Remove the author and date fields and the space associated with them
% from the definition of maketitle!
\makeatletter
\renewcommand{\@maketitle}{
\newpage
\null
\vskip 2em%
\begin{center}%
{\LARGE \@title \par}%
\end{center}%
\par} \makeatother
导出word表格到latex
关于将word中的表格直接转成相应latex代码的方法_NDnarg的博客-CSDN博客_word表格转latex
怎么在Excel中生成Latex代码——excel2latex插件_我这一次的博客-CSDN博客_excel2latex
VScode快速配置Latex
1、启动VScode下载插件LaTex Workshop;
2、插件安装完成后,输入命令>view latex 打开文档的预览窗口,快捷键是ctrl+Alt+v;
3、当点击保存编写的.tex文档时,上述插件会自动编译文档,并更新右端预览窗口,可在同级目录下找到对应的pdf文件;
4、可在左边Tex选项卡中找到插件LaTex Workshop可以提的全部功能;