Latex 语法

目录

一 .LaTeX中定义新命令和环境

二 .字体设置

三.中文处理方法

四.源文件基本结构

五.特殊字符

六.数学公式的多行公式

七.数学公式初步

八.篇章结构

九.矩阵

十.浮动体

十一.插图

十二.参考文献BibTex

十三.表格


一 .LaTeX中定义新命令和环境

% 导言区  
\documentclass{ctexart}%ctexbook, ctexrep  
  
% \newcommand{cmd}{def}定义命令  
% 命令只能由字母组成,不能以\end 开头  
% \newcommand{命令}[参数个数][首字母默认值]{具体定义}  
  
% \newcommand可以是简单字符串替代,例如:  
% 使用\PRC 相当于 People's Republic of \emph{China} 这一串内容  
\newcommand\PRC{People's Republic of \emph{China}}%\emph{text}表示强调  
  
% \newcommand也可以使用参数  
% 参数个数可以从1到9,使用时用 #1,#2,……,#9 表示  
\newcommand\loves[2]{#1 喜欢 #2}  
\newcommand\hatedby[2]{#2 不受 #1 喜欢}  
  
% \newcommand的参数也可以有默认值  
% 指定参数个数的同时指定了首个参数的默认值,那么这个命令的  
% 第一个参数就成为可选的参数(要使用中括号指定)  
\newcommand\love[3][喜欢]{#2#1#3}  
  
% \renewcommand-重定义命令  
% 与\newcommand 命令作用和用法相同,但只能用于已有命令  
% \renewcommand{cmd}[args][default]{def}  
\renewcommand\abstractname{内容简介}  
  
% 定义和重定义环境  
% \newenvironment{name}[args][default]{begdef}{enddef}  
% \renewenvironment{name}[args][default]{begdef}{enddef}  
  
% 为 book 类中定义摘要(abstract) 环境  
\newenvironment{myabstract}[1][摘要]%  
{\small  
    \begin{center}\bfseries #1\end{center}%  
    \begin{quotation}}%  
{      
    \end{quotation}  
}  
  
% 正文区(文稿区)  
\begin{document}  
    \PRC  
      
    \loves{猫儿}{鱼}  
      
    \hatedby{猫儿}{萝卜}  
      
    \love{猫儿}{鱼}  
      
    \love[最爱]{猫儿}{鱼}  
      
    \begin{abstract}  
        这是一段摘要...  
    \end{abstract}  
      
    \begin{myabstract}[我的摘要]  
        这是一段自定义格式的摘要...  
    \end{myabstract}  
      
\end{document}

二 .字体设置

在LATEX中,一个字体有5种属性:
- 字体编码
    - 正文字体编码:OT1、T1、EU1等
    - 数学字体编吗: OML、OMS、OMX等
- 字体族
    - 罗马字体:笔画起始处有装饰
    - 无衬线字体:笔画起始处无装饰
    - 打字机字体:每个字符宽度相同,又称等宽字体
- 字体系列
    - 粗细
    - 宽度
- 字体形状
    - 直立
    - 斜体
    - 伪斜体
    - 小型大写
- 字体大小
%导言区
\documentclass{article}

\usepackage{ctex}

\newcommand{\myfont}{\textit{\textbf{\textsf{Fancy Text}}}}

%正文区(文稿区)
\begin{document}
    %字体族设置(罗马字体、无衬线字体、打字机字体)
    \textrm{Roman Family} \textsf{Sans Serif Family} \texttt{Typewriter Family}
    {\rmfamily Roman Family}  {\sffamily Sans Serif Family} {\ttfamily Typewriter Family}

    {\sffamily who you are?you find self on everyone around. take  you as the same as others!}
    
    {\ttfamily Are you wiser than others? definitely no.in some ways, may it is true.What can you achieve? a luxurious house?a brillilant car? an admirable career?who knows?}

%字体系列设置(粗细、宽度)
    \textmd{Medium Series} \textbf{Boldface Series}
    {\mdseries Medium Series} {\bfseries Boldface Series}

%字体形状(直立、斜体、伪斜体、小型大写)
    \textup{Upright Shape} \text it{Italic Shape}
    \textsl{Slanted Shape} \textsc{Small Caps Shape}
    {\upshape Upright Shape} {\itshape Italic Shape} {\slshape Slanted Shape} {\scshape Small Caps Shape}

%中文字体
    {\songti 宋体} \quad {\heiti 黑体} \quad {\fangsong 仿宋} \quad {\kaishu 楷书}

中文字体的\textbf{粗体}与\textit{斜体}

%字体大小
    {\tiny            Hello}\\
    {\scriptsize             Hello}\\
    {\footnotesize       Hello}\\
    {\small                  Hello}\\
    {\normalsize        Hello}\\
    {\large                Hello}\\
    {\Large              Hello}\\
    {\LARGE           Hello}\\
    {\huge            Hello}\\
    {\Huge           Hello}\\
%中文字号设置命令
\zihao{-0} 你好!

\myfont
\end{document}

三.中文处理方法

%导言区
\documentclass{ctexart}%ctexbook, ctexrep

%usepackage(ctex)

\newcommand\degree{^\circ}
\ title{\heiti 杂谈勾股定理}
\author{\kaishu 张三}
\date{\today}
%正文区(文稿区)
\begin{document}
    \maketitle
    Hello World!
    
    %here is my big formula 
    
    Let $f(x)$ be defined by the formula
    $f(x)=3x^2+x-1$.

$$f(x)=3x^2+x-1$$
which is a polynomial of degree 2. 
设直角$\angel C=90\degree$
\begin{equation}
AB^2 =BC^2 + AC^2.
\end{equation}
%texdoc ctex
%texdoc lshort-zh
\end{document}

四.源文件基本结构

%导言区
\documentclass{article}%book, report, letter

\ title{My First Document}
\author{Nan Geng}
\date{\today}
%正文区(文稿区)
\begin{document}
    \maketitle
    Hello World!
    
    %here is my big formula 
    
    Let $f(x)$ be defined by the formula
    $f(x)=3x^2+x-1$.

$$f(x)=3x^2+x-1$$
which is a polynomial of degree 2. 
\end{document}

五.特殊字符

%导言区
\documentclass{article}

\usepackage{ctex}

%正文区(文稿区)
\begin{document}
    \section{空白符号}
     %空行分段,多个空行等同1个   
     %自动缩进,绝对不能使用空格代替
     %英文中多个空格处理为1个空格,中文中空格将被忽略
     %汉字与其它字符的间距会自动由XeLaTex处理
     %禁止使用中文全角空格(   \quad产生一个rem的空白,\qquad产生2rem的空白, \thinspace产生1\\6个em空白 ,\enspace产生0.5em个空白,\  命令输出一个空格,~命令产生一个硬空格)
     %1pc=12pt=4.218mm
     a\kern 1pc b
     a\kern -1em b
     a\hskip 1em b
     a\hspace{35pt}b
     %占位宽度
     a\hphantom{xyz}b
     %弹性长度
     a\hfill b
    \section{\LaTex 控制符}
    \# \$ \% \{\} \~{} \_{} \^{} \textbackslash \&
    \section{排版符号}
    \S \P \dag \ddag \copyright \pounds
    \section{\Tex 标志符号}
    \TeX{} \LaTeX{} \LaTeXe{}
    \section{引号}
    `' `` ''
    \section{连字符}
    - -- ---
    \section{非英文字符}
    \oe \OE \ae \AE \aa \AA \o \O \l \L \ss \SS !` ?`
    \section{重音符号}
    \`o \'o \^o \''o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \b{o} \c{o} \d{o}
\end{document}

六.数学公式的多行公式

%导言区
\documentclass{ctexart}%ctexbook,ctexrep

%\usepackage{ctex}
\usepackage{amsmath}
\usepackage{amssymb}

%正文区(文稿区)
\begin{document}

%带编号
    \begin{gather}
        a+b = b+a \\
        ab=ba
    \end{gather}
    
%不带编号
    \begin{gather*}
        a+b = b+a \\
        ab=ba
    \end{gather*}

%在\\前使用\notag阻止编号
\begin{gather}
3^2 + 4^2 = 5^2 \notag \\
5^2 + 12^2 = 13^2

%align 和align* 环境 (用 & 进行对齐)
\begin{align}
x &= t + \cos t + 1 \\
y &=2\sin t
\end{align}

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

%split环境(对齐采用align环境的方式,编号在中间)
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x - \sin^2 x \\
$= 2\cos^2 x -1
\end{split}
\end{equation}

%cases 环境
%每行公式中使用 & 分隔为两部分,
% 通常表示值和后面的条件
\begin{equation}
D(x) = \begin{cases}
1, & \text{如果} x \in \mathbb{Q}; \\
0, & \text{如果} x \in \mathbb{R}\setminus\mathbb{Q}.
\end{cases}
\end{equation}

\end{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^{20} - x +2 = 0$
$3x^{3x^{20} -x +2} -x + 2 =0$

\subsection{下标}
$a_0, a_1, a_2$
$a_0, a_1,a_2,...,a_{100}$
$a_0, a_1,a_2,...,a_{3x^{20} - x +2 = 0}$

\section{希腊字母}
$\alpha$
$\beta$
$\gamma$
$\epsilon$
$\pi$
$\omega$

$\Gamma$
$\Delta$
$\Theta$
$\Pi$
$\Omega$
\section{数学函数}
$\log$
$\sin$
$\cos$
$\arcsin$
$\arccos$
$\ln$

$\sqrt{2}$
$\sqrt{x^2 + y^2}$
$\sqrt{2+\sqrt{2}}$
$\sqrt[4]{x}$

\section{分式}
大约是原体积的$3/4$
大约是原体积的$\frac{3}{4}$

$\frac{x}{x^2+x+1}$
$\frac{\sqrt{x-1}}{\sqrt{x+1}}$
$\frac{1}{1+\frac{1}{x}}$
$\sqrt{\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}
    a+b=b+a \label{eq:commutative}
\end{equation}

subsection{不编号公式equation*环境}
%交换律见式\ref{eq:commutative2}:
\begin{equation*}
a+b=b+a%\label{eq:commutative2}
\end{equation*}
\usepackage{amsmath}

八.篇章结构

%导言区
\documentclass{ctexbook}%book, report, letter

\usepackage{ctex}

\ctexset{
    section = {
        format+ = \zihao{-4) \heiti \raggedright,
        name = {,、},
        number = \chinese{section},
        beforeskip = 1.0ex plus 0.2ex minus .2ex,
        afterskip = 1.0ex plus 0.2ex minus .2ex,
        aftername = \hspace{0pt}
        },
    subsection = {
        format+= \zihao{5} \heiti \raggedright,
        %name={\thesubsection、},
        name = {,、},
        number = \arabic{subsection},
        beforeskip = 1.0ex plus 0.2ex minus .2ex,
        afterskip = 1.0ex plus 0.2ex minus .2ex,
        aftername = \hspace{0pt}
        }
}
%正文区(文稿区)
\begin{document}
\tableofcontents 
\chapter{绪论}
    \section{引言}
    推荐系统是信息过载所采用的措施,面对海量的数据信息, 从中快速推荐出符合用户特点的物品。解决一些人的“选择 恐惧症”;面向没有明确需求的人。

    推荐系统是信息过载所采用的措施,面对海量的数据信息, 从中快速推荐出符合用户特点的物品。解决一些人的“选择 恐惧症”;面向没有明确需求的人。\par解决如何让自己生产的信息脱颖而出,受到大众的喜爱。
    
\section{实验方法}
    \section{实验结果}
    \subsection{数据}
    \subsection{图表}
    \subsubsection{实验条件}
    \subsubsection{实验过程}
    \subsection{结果分析}
    \section{结论}
    \section{致谢}
\end{document}

九.矩阵

%导言区
\documentclass{ctexart}%ctexbook, ctexrep

%\usepackage{ctex}
\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}
    \]

pmatrix%小括号
bmatrix%中括号
Bmatrix%大括号
vmatrix%单竖线
Vmatrix%双竖线

%矩阵环境,用&分隔列,用\\分隔行

%可使用上下标
\[
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、\cdots、\adots
乘号 \times
\[
A = \begin{bmatrix}
a_{11} & \dots & a_{1n}\\
\adots & \ddots & \vdots \\
0 && a_{nn}
\end{bmatrix}_{n \times n}
\]

%分块矩阵(矩阵嵌套)
\[
\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}
\]

%三角矩阵
\[\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
& a_{22} & \cdots &a_{2n} \\
&            & \ddots & \vdots \\
\multitolumn{2}{c}{\raisebox{1.3ex}[0pt]{\Huge 0}}
&                 &a_{nn}
\end{pmatrix}
\]

%跨列的省略号:\hdotsfor{<列数>}
\[
\begin{pmatrix}
1 & \frac 12 & \dots & \frac 1n \\
\hdotsfor{4} \\
m & \frac m2 & \dots & \frac mn
\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}
\frac12 & 0 \\
\hline
0 & -\frac abc \\
\end{array}
\]

\[

\begin{array}{c@{\hspace{-5pt}}l}

\left(

\begin{array}{ccc|ccc}

a & \cdots & a & b & \cdots & b \\

& \ddots & \vdots & \vdots & b\\

&           & a & b \\ \hline

&           &    & c & \cdots & c\\

&           &    & \vdots & & \vdots\\

\multicolumn{3}{c|}{\raisebox{2ex}[0pt]{\Huge 0}}

& c & \cdots & c

\end{array}

\right)

&

% 第1行第2列

\begin{array}{l}

%\left.仅表示与\right\}配对,什么都不输出

\left.\rule{0mm}{7mm}\right\}p\\

\\

\left.\rule{0mm}{7mm}\right\}q

\end{array}

\\[-5pt]

% 第2行第1列

\begin{array}{cc}

\underbrace{\rule{17mm}{0mm}}_m &

\underbrace{\rule{17mm}{0mm}}_m

\end{array}

& %第2行第2列

\end{array}

\]
\end{document}

十.浮动体

%导言区
\documentclass{ctexart}%ctexbook,ctexrep

%\usepackage{ctex}

%正文区(文稿区)
\begin{document}
    \LaTex{}中\Tex系统的吉祥物---小狮子见图\ref{fig-lion}:
    \begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.3]{lion}
    \caption{\Tex 系统的吉祥物---小狮子}\label{fig-lion}
    \end{figure}
    当然在\LaTex{}中的表格\ref{tab-score}:
    \begin{table}[h]
        \centering
        \caption{考试成绩单}\label{tab-score}
    \begin{tabular}{|l | | c  |  c  | c  | p{1.5cm}|}
    \hline
    姓名 & 语文 & 数学 & 外语 & 备注 \\
    \hline \hline
    张三 & 87 & 100 & 93 & 优秀 \\
    \hline
    李四 & 75 & 64 & 52 & 补考另行通知 \\
    \hline
    王二 & 80 & 82 & 78 & \\
    \hline
    \end{tabular}
    \end{table}
    texdoc booktab
    texdoc longtab
    texdoc tabu
    %<允许位置>参数(默认tbp)
    %h,此处(here)-代码所在的上下文位置
    %t, 页项(top)-代码所在页面或之后页面的顶部
    %b,页底(bottom)-代码所在页面或之后页面的底部
    %p,独立一页(page)-浮动页面

    %标题控制(caption、bicaption等宏包)
    %并排与子图表(subcaption、subfig、floatrow等宏包)
    %绕排(picinpar、wrapfig等宏包)
\end{document}

十一.插图

%导言区
\documentclass{ctexart}%ctexbook,ctexrep

%\usepackage{ctex}

%导言区:\usepackage{graphicx}
%语法:\includegraphics[<选项>]{<文件名>}
%格式: EPS, PDF, PNG, JPEG,BMP
\usepackage{graphicx}
\graphicspath{{figures/},{pics/}%图片在当前目录下的figures目录

%正文区(文稿区)
\begin{document}
    \LaTex{}中的插图:
    
    \includegraphics{lion.eps}
    \includegraphics{mountain.jpg}
    \includegraphics{oscilloscope.pdf}

    \includegraphics[scale=0.3]{lion}
    \includegraphics[scale=0.03]{mountain}
    \includegraphics[scale=0.3](oscilloscope)

    \includegraphics[height=2cm]{lion}
    \includegraphics[height=2cm]{mountain}
    \includegraphics[height=2cm]{oscilloscope}

    \includegraphics[height=0.1\textheight]{lion}
    \includegraphics[height=0.1\textheight]{mountain}
    \includegraphics[height=0.1\textheight]{oscilloscope}

    \includegraphics[width=0.2\textheight]{lion}
    \includegraphics[width=0.2\textheight]{mountain}
    \includegraphics[width=0.2\textheight]{oscilloscope}

    \includegraphics[angle=-45,width=0.2\textheight]{lion}
    \includegraphics[width=0.2\textheight]{mountain}
    \includegraphics[angle=45,width=0.2\textheight]{oscilloscope}
\end{document}

十二.参考文献BibTex

1.  在构件中设置默认文献工具为BibTex
2.  在谷歌学术中点击引用链接获取BibTex格式的数据
3.  新建.bib后缀的文件,复制获取参考文献数据

% 导言区  
\documentclass{ctexart}%ctexbook, ctexrep  
  
%\usepackage{ctex}  
  
\bibliographystyle{plain}%指定排版样式 如plain unsrt alpha abbrv  
  
% 正文区(文稿区)  
\begin{document}  
    %一次管理,一次使用  
    %参考文献格式:  
    %\begin{thebibliography}{编号样本}  
    %    \bibitem[label]{citekey}文献条目1  
    %   \bibitem[label]{citekey}文献条目2  
    %    ……  
    %\end{thebibliography}  
    %其中文献条目包括:作者,题目,出版社,年代,版本,页码等。  
    %引用时候要可以采用:\cite{引用标志1,引用标志2,……}  
    引用一本Guide\cite{latexGuide}等等  
    \begin{thebibliography}{99}  
        \bibitem{latexGuide} Kopka Helmut, W. Daly Patrick,  
        \emph{Guide to \LaTeX}, $4^{th}$ Edition.  
        Available at \texttt{http://www.amazon.com}.  
    \end{thebibliography}  
    这是一个参考文献的引用:\cite{scott1988social}  
    \bibliography{test}  
\end{document}

### bib文件如下
  @article{scott1988social,  
  title={Social network analysis},  
  author={Scott, John},  
  journal={Sociology},  
  volume={22},  
  number={1},  
  pages={109--127},  
  year={1988},  
  publisher={British Sociological Association Publications Limited}  
}

十三.表格

%导言区
\documentclass{ctexart}%ctexbook,ctexrep

%\usepackage{ctex}

%正文区(文稿区)
\begin{document}
    \begin{tabular}{|l | | c  |  c  | c  | p{1.5cm}|}
    \hline
    姓名 & 语文 & 数学 & 外语 & 备注 \\
    \hline \hline
    张三 & 87 & 100 & 93 & 优秀 \\
    \hline
    李四 & 75 & 64 & 52 & 补考另行通知 \\
    \hline
    王二 & 80 & 82 & 78 & \\
    \hline
    \end{tabular}
    texdoc booktab
    texdoc longtab
    texdoc tabu
\end{document}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值