LaTeX排版(二)

一、LaTeX数学公式初步
1.代码展示

%导言区
\documentclass{article}
\usepackage{ctex}
\usepackage{amsmath}

%正文区
\begin{document}
	\section{简介}
	\LaTeX{} 将排版内容分为文本模式和数学模式。文本模式用于普通文字的排版,数学模式用于数学公式排版。
	\section{行内公式}
	\subsection{美元符号}
	交换律是 $a+b=b+a$,如 $1+2=2+1=3$。
	\subsection{小括号}
	交换律是 \(a+b=b+a\),如 \(1+2=2+1=3\)。%使用\引出了左右括号
	\subsection{math环境}
	交换律是 \begin{math}a+b=b+a\end{math},如\begin{math}1+2=2+1=3\end{math}
	\section{上下标}
	\subsection{上标}
	$3x^2-x+2=0$
	
	$3x^{20}-x+2=0$   %使用{}来进行分组从而实现相应的排版
	
	$3x^{3x^{20}-x+2}-x+2=0$
	\subsection{下标}%使用下划线来实现
	$a_0,a_1,a_2,...a_{100},a_{3x^{20}-x+2}$
	\section{希腊字母}
	$\alpha$
	$\beta$
	$\gamma$
	$\epsilon$
	$\pi$
	$\omega$
	
	$\Gamma$
	$\Delta$
	$\Theta$
	$\Pi$
	$\Omega$
	
	$\alpha^2+\beta^2+\gamma=0$
	\section{数学函数}
	$\log$
	$\sin$
	$\cos$
	$\arccos$
	$\arcsin$
	$\ln$
	
	$\sin^2 x+\cos^2 x=1$
	$y=\sin^{-1} x$
	$y=log_2 x$
	
	$\sqrt{2}$
	$\sqrt{x^2+\sqrt{2}}$
	$\sqrt[4]{x}$ %可选次数可用于规定开方次数
	\section{分式}
	大约是原体积的$3/4$.
	大约是原体积的$\frac{3}{4}$  %/frac的第一个参数是分子,第二个参数是分母
	
	$\frac{\sqrt{x-1}}{\frac{x}{x^2+x+1}}$
	
	\section{行间公式}
	\subsection{美元符号}
	交换律是 $$a+b=b+a$$ 如 $$1+2=2+1=3$$。
	
	\subsection{中括号}
	交换律是
	\[a+b=b+a\] 
	如 
	\[1+2=2+1=3\]。
	
	\subsection{displaymath环境}
	交换律是 \begin{displaymath}a+b=b+a\end{displaymath}
	如
	\begin{displaymath}1+2=2+1=3\end{displaymath}
	
	\subsection{自动编号公式equation环境}
	交换律公式见式\ref{eq:commutative}
	\begin{equation}%equation用于对公式进行编号
		a+=b+a \label{eq:commutative}
	\end{equation}
	
	\subsection{不编号公式equation*环境}
	交换律公式见式\ref{eq:commutative2}
	\begin{equation*}%equation用于对公式进行编号,需使用\usepackage{amsmath}
	a+=b+a \label{eq:commutative2}
	\end{equation*}
	
	公式的编号和交叉引用也是自动实现的,大家在排版中,要习惯于采用自动化的方式处理诸如图、表、公式的编号和交叉引用。
\end{document}

2.结果展示
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
二、LaTex数学模式中的矩阵

%导言区
\documentclass{ctexart}
\usepackage{amsmath}
\newcommand{\adots}{\mathinner{\mkern2mu%
		\raisebox{0.1em}{.}\mkern2mu\raisebox{0.4em}{.}%
		\mkern2mu\raisebox{0.7em}{.}\mkern1mu}}
%正文区
\begin{document}
	%矩阵环境,用&分隔列,用\\分隔行
	\[
	\begin{matrix}
		0 & 1\\
		1 & 0
	\end{matrix} \qquad
	\begin{pmatrix} %用于加括号
		0 & 1\\
		1 & 0
	\end{pmatrix} \qquad
	\begin{bmatrix} %用于加中括号
		0 & 1\\
		1 & 0
	\end{bmatrix} \qquad
	\begin{Bmatrix} %用于加大括号
		0 & 1\\
		1 & 0
	\end{Bmatrix} \qquad
	\begin{vmatrix} %用于加单竖线
		0 & 1\\
		1 & 0
	\end{vmatrix} \qquad
	\begin{Vmatrix} %用于加双竖线
		0 & 1\\
		1 & 0
	\end{Vmatrix} \qquad
	\]
	
	
	%可以使用上下标
	\[
	A=\begin{pmatrix}
	a_{11}^2 & a_{12}^2 &a_{13}^2\\
	0 & a_{22} & a_{23}\\
	0 & 0& a_{33}
	\end{pmatrix}
	\]
	
	%常用省略号:$\dots$、\vdots、$\ddots$
	\[
	A=\begin{bmatrix}
	a_{11} & \dots & a_{1n}\\
	\adots & \ddots& \vdots\\
	0 & & a_{nn}
	\end{bmatrix}_{n \times n}  %在数学命令中,可以\times来排版乘号
	\]
			
	%分块矩阵
	\[
	\begin{pmatrix} 
	\begin{matrix}1&0 \\0&1\end{matrix}
	& \text{\Large 0}\\
	\text{\Large 0} & \begin{matrix}1&0 \\0&-1\end{matrix}
	\end{pmatrix}
	\]%\text{}用于在数学模式中临时切换到文本模式
	
	%三角矩阵
	\[\begin{pmatrix}
	a_{11} & a_{12} & \cdots &a_{1n}\\
	& a_{22} & \cdots & a_{2n}\\
	&        & \ddots & \vdots\\
	\multicolumn{2}{c}{\raisebox{1.3ex}[0pt]{\Huge 0}}   %\multicolumn{cols}{pos}{text}可用于合并多列;\raisebox来调整高度
	&        &a_{nn}
	\end{pmatrix}	
	\]
	
	%跨列的省略号:\hdotsfor{<列数>}
	\[
	\begin{pmatrix}
	1 & \frac{1}{2} & \dots & \frac{1}{n}\\
	\hdotsfor{4}\\  %用于产生扩列省略号
	m & \frac{m}{2} & \dots & \frac{m}{n}
	\end{pmatrix}
	\]
	
	%行内小矩阵(smallmatrix)环境
	复数 $z=(x,y)$也可用矩阵
	\begin{math}
		\left(%需手动加上左括号
		\begin{smallmatrix}
		x & -y \\ y & x
		\end{smallmatrix}
		\right)%需手动加上右括号
	\end{math}来表示。
	
	%array环境(类似表格环境tabular)
	\[
	\begin{array}{r|r}
	\frac 12 & 0\\
	\hline
	0 & -\frac abc \\%\frac后不能字节跟随字母会产生语法错误
	\end{array}
	\]
	
	
	%array环境可以排版更为复杂的矩阵
	\[
	% @{<内容>}--添加任意内容,不加表项计数
	% 此处添加一个负值空白,表示左移-5pt的 距离
	\begin{array}{c@{\hspace{-5pt}}l}  %c指定第一列居中对齐,l指定最后一列居左对齐
	%第一行第一列
	\left(%产生矩阵左侧的小括号定界符
	\begin{array}{ccc|ccc}
	a& \cdots & a & b & \cdots & b\\
	& \ddots & \vdots & \vdots & \adots\\
	&        & a & b\\ \hline
	&        &   & c & \cdots & c\\
	&        &   & \vdots & & \vdots\\
	\multicolumn{3}{c|}{\raisebox{2ex}[0pt]{\Huge 0}}
	& c & \cdots & c 	
	\end{array}
	\right)%产生矩阵右侧的小括号定界符
	&
	% 第一行第二列,右侧的大括号标示符
	\begin{array}{l}
	%$\left.仅表示与\right\}配对,什么都不输出
	\left.\rule{0mm}{7mm}\right\}p\\ %\rule命令指定大括号的尺寸
	\\
	\left.\rule{0mm}{7mm}\right\}q
	\end{array}
	\\[-5pt]
	%第二行第一列
	\begin{array}{cc}
	\underbrace{\rule{17mm}{0mm}}_m& %\rule命令指定大括号的尺寸
	\underbrace{\rule{17mm}{0mm}}_m
	\end{array}
	&%第二行第二列
	\end{array}
	\]
\end{document}

三、LaTeX中的多行数学公式
首先,应注意使用的包环境

\documentclass{ctexart}
\usepackage{amsmath}
\usepackage{amssymb}
  1. gather和gather*环境(可以使用\换行)
	% 带编号
	\begin{gather}%gather环境可以实现多行公式的排版
		a+b=b+a\\
		ab ba
	\end{gather}
	
	% 不带编号
	\begin{gather*}%gather环境可以实现多行公式的排版
	3+5=5+3=8\\
	3 \times 5 =5 \times 3
	\end{gather*}

结果:
在这里插入图片描述
2.在\前使用\notag阻止编号

	\begin{gather}
		a+b=b+a \notag\\
		ab ba
	\end{gather}

结果
在这里插入图片描述
3.align 和align*环境(用&进行对齐)

	% 带编号
	\begin{align}
		x &=t+\cos t +1 \\
		y &=2\sin t
	\end{align}
	
	%不带编号
	\begin{align*}
	x &=t+\cos t +1 & x &=t+\cos t +1 & x &=t+\cos t +1 \\
	y &=2\sin t & x &=t+\cos t +1 & x &=t+\cos t +1
	\end{align*}

在这里插入图片描述
4.split环境(对齐采用align环境的方式,编号在中间)

	\begin{equation}%实现一个公示的多行排版
		\begin{split}
		\cos  2z &=\cos^2 x-\sin62 x\\
		&=2\cos^2 x-1
		\end{split}
	\end{equation}

5.case环境 可实现分段函数的排版

	%case环境 可实现分段函数的排版
	% 每个公式使用&分隔为两部分,
	% 通常表示值和后面的条件
	\begin{equation}
		D(x)=\begin{cases}
			1,&\text{如果} x \in \mathbb{Q};\\  %\in用于输出属于符号,\mathbb{}命令用于输出花体字符;\text用于在数学模式中临时切换到文本模式
			0,&\text{如果} x \in \mathbb{R}\setminus\mathbb{Q}
		\end{cases}
	\end{equation}

四、LaTeX中的参考文献-BibTeX
1.基础版本(不利于管理和使用)
相应代码:

%引言区
\documentclass{ctexart}
%正文区
\begin{document}
	%一次管理,一次使用
	%参考文献格式
	%\begin{thebibliiography}{编号样本}
	% \bibitem[记号]{引用标志}文献条目1
	% \bibitem[记号]{引用标志}文献条目2
	%\end{thebibliiography}
	%其中文献条目包括:作者,题目,出版社,年代,版本,页码 等。 
	%引用的时候可以采用:\cite{引用标志1,引用标志2,...}
	引用一篇文章\cite{article1} 应用一本书\cite{book1}
	\begin{thebibliography}{99}
		%\bibitem{article} 用于一条参考文献条目描述;\emph{text}可以用于强调参考文献中的某些内容
		\bibitem{article1}陈立辉,苏伟,蔡川,陈晓恽.\emph{基于LaTeX的Web数学公式提取方法研究}[J].计算机科学.2014(06)
		\bibitem{book1}William H.Press,Saul A.Teukolsky,
		william T.Vetterling ,Brian P.Flannery,
		\emph{Numerical Recipes 3rd Edition:
			The Art of Scientific Computing}
		Cambridge University Press,New York,2007.
		\bibitem{latexGuide}Kopka Helmut,W. Daly Patrick,
		\emph{Guide to \LaTeX},$4{th}$ Edition.
		Available at\texttt{http://www.amazon.com}
		\bibitem{latexMath} Graetzer George,\emph{Math Into \LaTeX},
		BirkAuser Boston;3 edition(Iune 22,2020).
	\end{thebibliography}
\end{document}

在这里插入图片描述
2.高级版本
(1).数据库文件的代码test.bib

@BOOK{mittelbach2004,
title={The {{\LaTeX}} Companion},
publisher={Addison-wesley},
year={2004},
author={Frank Mittelbach and Michel Goossensh},
series={Tools and Techniques for Computer Typesetting},
address ={Boston},
edition={second}
}
@misc{patashnik1988designing,
	title={Designing BIBTEX styles},
	author={Patashnik, Oren},
	year={1988},
	publisher={February}
}

(2).latexRefence.tex

%引言区
\documentclass{ctexart}
\bibliographystyle{plain} %指定参考文献的排版样式

%正文区
\begin{document}
	这是一个参考文献的引用:\cite{mittelbach2004} %相应条目的标识符
	
	这是另一个引用:\cite{patashnik1988designing}
	\nocite{*} %在参考文献列表中排版未引用的参考文献 *指的是排版所有参考文献
	\bibliography{test} %指定参考文献数据库
\end{document}

(3).结果显示
在这里插入图片描述
(4).参考文献更改后,需要进行如下操作
在这里插入图片描述
五、LaTeX中的参考文献-BibLaTeX
首先,应先设置模式Biber。
在这里插入图片描述
(1)test.bib

@BOOK{mittelbach2004,
	title={The {{\LaTeX}} Companion},
	publisher={Addison-wesley},
	year={2004},
	author={Frank Mittelbach and Michel Goossensh},
	series={Tools and Techniques for Computer Typesetting},
	address ={Boston},
	edition={second}
}
@misc{patashnik1988designing,
	title={Designing BIBTEX styles},
	author={Patashnik, Oren},
	year={1988},
	publisher={February}
}
@online{6-1,
	title = {PACS-L: the public-access computer systems forum},
	type = {EB/ OL},
	publisher = {university of Houston Libraries},
	year = {1989},
	url={http://info.1ib.uh.edu/pacsl.html},
	urldate = {1995-05-17},
	language = {english}
}

(2).latexRefBibLaTeX.tex

\documentclass{ctexart}
%\usepackage{ctex}
% biblatex/biber
% 新的TEX参考文献排版引擎
% 样式文件(参考文献样式文件--bbx文件,引用样式文件-cbx)使用 LATEX编写
% 支持根据本地化排版,如:
% biber-l zh_pinyin texfile,用于指定按拼音排序
% biber-l zh stroke texfile,用于按笔画排序
\usepackage[style=numeric,backend=biber]{biblatex}%样式为numberic,后端为biber
\addbibresource{test.bib} %此处不可省略用户名
%正文区(文稿区)
\begin{document}
	%一次管理,多次使用
	%无格式化引用\cite{biblatex}
	无格式化引用\cite{mittelbach2004}
	带方括号的引用\parencite{patashnik1988designing}
	上标引用\supercite{6-1}
	
	\printbibliography[title={参考文献}]%输出参考文献列表,默认为References
\end{document}

(3)结果显示
在这里插入图片描述
六、LaTeX中定义新命令和环境
1.内容与格式分离的思想

%导言区
\documentclass{ctexart}

%\newcommand-定义命令
%命令只能由字母组成,不能以\end开头
%\newcommand<命令>[<参数个数>][<首参数默认值>][<具体定义>]

%\newcommand可以是简单的字符串替换,例如:
% 使用\PRC 相当于People's Republic of \emph{China}这一串内容
\newcommand\PRC{People's Republic of \emph{China}}
%正文区
\begin{document}
	\PRC
\end{document}

2.newcommand也可以使用参数

%导言区
\documentclass{ctexart}
%\newcommand也可以使用参数
%参数个数可以是1到9,使用时用#1,#2,.....,#9表示
\newcommand\loves[2]{#1 喜欢 #2}
\newcommand\hatedby[2]{#2 不受 #1 喜欢} 
%正文区
\begin{document}
	\loves{猫儿}{}
	
	\hatedby{猫儿}{萝卜}
\end{document}

3.\newcommand的参数也有默认值

%导言区
\documentclass{ctexart}
% 指定参数个数的同时指定了首个参数的默认值,那么这个命令的 第一个参数就成为了可选的参数(要使用中括号指定)
\newcommand\love[3][喜欢]{#2#1#3}
%正文区
\begin{document}
	\love{猫儿}{}
	\love[最爱]{猫儿}{}
\end{document}

4.renewcommand重新定义命令

%导言区
\documentclass{ctexart}
% \renewcommand{cmd}{def}--重定义命令
% 与\newcommand的作用相同,但只能用于已有命令
% \renewcommand<命令>[<参数个数>][<首参数默认值>][<具体定义>]
\renewcommand\abstractname{内容简介}
%正文区
\begin{document}
	\begin{abstract}
		这是一段摘要...
	\end{abstract}
\end{document}

在这里插入图片描述
5.定义和重定义新环境
(1)定义环境时,使用默认参数

%导言区
\documentclass{ctexart}
%定义和重定义新环境
%\newenvironment{<环境名称>}[<参数个数>][<首参数默认值>]
%				{<环境前定义>}
%				{<环境后定义>}
\newenvironment{myabstract}[1][摘要]
{\small
	\begin{center}\bfseries #1\end{center}%
	\begin{quotation}}%
	{\end{quotation}}
%正文区
\begin{document}
	\begin{myabstract}
		这是一段自定义格式的摘要...
	\end{myabstract}
\end{document}

在这里插入图片描述
(2)定义环境时,指定参数
在这里插入图片描述
在这里插入图片描述
(3)重新定义新环境

%导言区
\documentclass{ctexart}
% <环境后定义>中不能再使用环境参数。
% 如果需要,可以先把前面得到的参数保存在一个命令中,在后面使用
\newenvironment{Quotation}[1]%
{\newcommand\quotesource{#1}%
	\begin{quotation}}%
	{\par\hfill---《\textit{\quotesource}》%
	\end{quotation}}

%正文区
\begin{document}
	\begin{Quotation}{易$\cdots$乾}
		初九,潜龙勿用.
	\end{Quotation}
\end{document}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_36717487/article/details/106864008