LaTeX 源文件的基本结构
LaTeX 分为“导言区”与“文稿区”。
-
导言区
- 在导言区对文章进行全局设置
- 常会使用
\documentclass{...}
命令,大括号内常有article
、book
、report
、letter
等 - 可以使用
\title
命令输入文章的标题 - 可以使用
\author
命令输入作者姓名 - 可以使用
\date
命令输入写作时间,同时用\today
命令今天的日期
-
正文区
- 会使用
\begin
与\end
渲染编译环境,二者之间为输出内容,常有\begin{document}
与\end{document}
- 注意常在正文区输入
\maketitle
输出标题
- 会使用
%导言区 \documentclass{article} \title{The First Article} \author{Ron} \date{\today} %文稿区 \begin{document} \maketitle Hello World! Let $f(x)$ be defined by the formula $$f(x)=3x^2+x-1$$ which is a polynomial of degree 2. \end{document}
%
后输入注释的内容,注释的内容不会进行编译$
与$
之间输入行内公示- 在
$$
后输入行间公式 - 在源文件中的两行代码之间加入一个空行,可以实现换行的操作,但注意,多个空行会对视为一个空行进行处理
编译效果如下:
LaTeX 中的中文处理办法
❗ 确保编译器为 XeLaTeX,编码为 UTF-8
❗ 在导言区加入
\usepackage{ctex}
%导言区 \documentclass{article} \usepackage{ctex} \newcommand\degree{^\circ} \title{\heiti 勾股定理} \author{\kaishu 张三} \date{\today} %文稿区 \begin{document} \maketitle 勾股定理可以用现代语言表述如下: 直角三角形斜边的平方等于两腰平方和 可以用符号语言表述为:设直角三角形$ABC$,其中$\angle C=90 \degree $,则有: \begin{equation} AB^2=BC^2+AC^2 \end{equation} \end{document}
- 代码中的
\newcommand\degree{^\circ}
用于定义正文区\degree
的含义 \heiti
和\kaishu
分别表示字体为黑体和楷书\equation
用于渲染带标号公式的编译环境
编译效果如下:
‼️ 如果在导言区中的 \documentclass{...}
中输入 \ctexart
、\ctexrep
、\ctexbook
(分别对应 \article
、\report
、\book
),可以不用使用 \usepackage{ctex}
LaTeX 的字体字号设置
字体属性
-
字体编码
- 正文字体编码:OT1、T1、EU1 等
- 数字字体编码:OML、OMS、OMX 等
-
字体族
- 罗马字体:笔画起始处有装饰
- 无衬线字体:笔画起始处无装饰
- 打字机字体:每个字符宽度相同,又称等宽字体
-
字体大小
-
字体系列
- 粗细
- 宽度
-
字体形状
- 直立
- 斜体
- 伪斜体
- 小型大写
字体族设置
- 罗马体:
\textrm
或\rmfamily
- 无衬线字体:
\textsf
或\sffamily
- 打字机字体:
\texttt
或\ttfamily
\textrm{Roman Family} \textsf{Sans Serif Family} \texttt{Typewriter Family} {\rmfamily Roman Family} {\sffamily Sans Serif Family} {\ttfamily Typewriter Family}
{}
的作用为限制设置命令或设置声明的作用区域
字体系列设置
- 普通粗细:
\textmd
或\mdseries
- 加粗:
\textbf
或\bfseries
\textmd{Medium Series} \textbf{Boldface Series} {\mdseries Medium Series} {\bfseries Boldface Series}
字体形状
- 直立:
\textup
或\upshape
- 斜体:
\textit
或\itshape
- 伪斜体:
\textsl
或\slshape
- 小型大写:
\textsc
或\scshape
\textup{Upright Shape} \textit{Italic Shape} \textsl{Slanted Shape} \textsc{Small Caps Shape} {\upshape Upright Shape} {\itshape Italic Shape} {\slshape Slanted Shape} {\scshape Small Caps Shape}
中文字体
- 宋体:
\songti
- 黑体:
\heiti
- 仿宋:
\fangsong
- 楷书:
\kaishu
{\songti 宋体} {\heiti 黑体} {\fangsong 仿宋} {\kaishu 楷书}
字体大小
字体大小的编译效果是相对于“基本大小”而确立的,字体的“基本大小”,即文档类参数,可以在导言区中的
\documentclass
后加入[]
中确定,可以自由设置,如:\documentclass[10pt]{article}
\tiny
\scriptsize
\footnotesiz
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
中文字号设置命令
-
\zihao{}
\zihao{0}
表示“初号”\zihao{-0}
表示“小初号”- 可类推之其余字号,
{}
中的数字表示“几号”,加上-
表示“小几号”
❗ 常常会在导言区使用
\newcommand
命令统一设置字体字号
编译总结
\documentclass{article} \usepackage{ctex} \newcommand{\myfont}{\textit{\textbf{\textsf{The Text}}}} \title{\heiti LaTeX的字体字号设置} \begin{document} \maketitle 下面是字体族设置: \textrm{Roman Family} \textsf{Sans Serif Family} \texttt{Typewriter Family} {\rmfamily Roman Family} {\sffamily Sans Serif Family} {\ttfamily Typewriter Family} 下面是字体系列设置: \textmd{Medium Series} \textbf{Boldface Series} {\mdseries Medium Series} {\bfseries Boldface Series} 下面是字体形状设置: \textup{Upright Shape} \textit{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 楷书} 下面是字体大小的设置 {\tiny Hello}\\ {\scriptsize Hello}\\ {\footnotesize Hello}\\ {\small Hello}\\ {\normalsize Hello}\\ {\large Hello}\\ {\Large Hello}\\ {\LARGE Hello}\\ {\huge Hello}\\ {\Huge Hello} \myfont \end{document}
LaTeX 的篇章结构
\section
命令
- 使用
\section
命令构建提纲,如引言、结论等小节 - 使用
\subsection
构建子小节 - 使用
\subsubsection
构建三级小节
❗
\\
与\par
的区别
\\
换行不缩进\par
换行且缩进
为了使代码结构清晰,换行分段常常使用“空行”实现
\chapter
命令
用于产生章节,常在 \documentclass{book}
的命令下使用,使用 \chapter
时 \subsubsection
命令不起作用
\tableofcontents
命令
用于产生目录
\documentclass{article} \usepackage{ctex} \title{\heiti LaTeX的篇章结构} \begin{document} \maketitle \tableofcontents \section{引言} 近年来,随着逆向工程和三维重建技术的发展和应用,获取现实世界中物体的三维数据的方法受到越来越多的关注和研究,很多研究机构和商业公司都陆续推出了自己的三维重建系统。 近年来,随着逆向工程和三维重建技术的发展和应用,获取现实世界中物体的三维数据的方法受到越来越多的关注和研究,\\很多研究机构和商业公司都陆续推出了自己的三维重建系统。 近年来,随着逆向工程和三维重建技术的发展和应用,获取现实世界中物体的三维数据的方法受到越来越多的关注和研究,\par 很多研究机构和商业公司都陆续推出了自己的三维重建系统。 \section{实验方法} \section{实验结果} \subsection{数据} \subsection{图表} \subsubsection{实验条件} \subsubsection{实验过程} \subsection{结果分析} \section{结论} \section{致谢} \end{document}
LaTeX 中的特殊字符
空白字符
-
LaTeX 中
- 空行分段,多个空行等同 1 个
- 自动缩进,绝对不能使用空格代替
- 英文中多个空格处理为一个空格,中文中空格将被忽略
- 汉字与其他字符的间距会自动由 XeLaTeX 处理
- 禁止使用中文全角空格
空格命令
-
\quad
,产生 1 em(当前字体中 M 的宽度)的空格 -
\qquad
,产生 2 em 的空格 -
\,
或\thinspace
产生 1/6 em 的空格 -
\enspace
产生 0.5 em 个空格 -
\
+(space)
输出一个空格 -
~
输出硬空格(不可被分割的空格) -
\kern
或\hskip
产生指定宽度的空白- 产生空白的长度可以使用负值
- 1pc=12pt=4.218em
-
\hspace
根据指定宽度产生空白 -
\hphantom
根据指定参数的占位字符的宽度产生空白 -
\hfill
产生弹性长度的空白(撑满整行)
LaTeX 控制符
代码 | \# |
\$ |
\% |
\{ |
\} |
\~{} |
\_{} |
\^{} |
\& |
---|---|---|---|---|---|---|---|---|---|
对应符号 | # | $ | % | { | } | ~ | _ | ^ | & |
❗“\”的输出需要用到
\textbackslash
命令
LaTeX 排版符号
代码 | \S |
\P |
\dag |
\ddag |
\copyright |
\pounds |
---|---|---|---|---|---|---|
对应符号 | \S | \P | \dag | \ddag | \copyright | \pounds |
TeX 标志符号
代码 | \TeX{} |
\LaTeX{} |
\LaTeXe{} |
---|---|---|---|
对应符号 | \TeX{} | \LaTeX{} | \LaTeX {2\varepsilon} |
引号
代码 | ```(撇号) | ' (单引号) |
```` | '' |
---|---|---|---|---|
对应符号 | ‘ | ’ | “ | ” |
连字符
代码 | - |
-- |
--- |
---|---|---|---|
对应符号 | - | - | — |
用处 | 连字符 | 表示数字范围 | 破折号 |
非英文字符
代码 | \oe |
\OE |
\ae |
\AE |
\aa |
\AA |
\o |
\O |
---|---|---|---|---|---|---|---|---|
对应符号 | $ $ | \aa | \AA | |||||
代码 | \l |
\L |
\ss |
\SS |
`!`` | `?`` | ||
对应符号 |
重音字符
代码 | \ a` |
\'a |
\^a |
\''a |
\"a |
\~a |
\=a |
\.a |
---|---|---|---|---|---|---|---|---|
对应符号 | \`a | \'a | \^a | \"a | \~a | \=a | \.a | |
代码 | \u{a} |
\v{a} |
\H{a} |
\r{a} |
\t{a} |
\b{a} |
\c{a} |
\d{a} |
对应符号 | \u{a} | \v{a} | \H{a} | \r{a} | \c{a} |
\documentclass{article} \usepackage{ctex} \title{\heiti \LaTeX{}中的特殊字符} \begin{document} \maketitle \section{空白字符} aMb\par a\quad b \qquad a\textbackslash quad b\par a\qquad b \qquad a\textbackslash qquad b \par a\,b , a\thinspace b \qquad a\textbackslash,b 或a\textbackslash thinspace b \par a\enspace b \qquad a\textbackslash enspace b\par a\ b \qquad a\textbackslash \ b\par a~b \qquad a\~{}b\par a\kern 1pc b \qquad a\textbackslash kern 1pc b\par a\kern -1em b \qquad a\textbackslash kern -1em b\par a\hskip 1em b \qquad a\textbackslash hskip 1em b\par a\hspace{35pt}b \qquad a\textbackslash hspace\{35pt\}b\par a\hphantom{xyz}b \qquad a\textbackslash hphantom\{xyz\}b\par a\hfill b a\textbackslash hfill b \section{\LaTeX 控制符} \# \quad \$ \quad \% \qquad \{ \quad \} \quad \~{} \quad \_{} \quad \^{} \quad \& \quad \textbackslash \section{排版符号} \S \quad \P \quad \dag \quad \ddag \quad \copyright \quad \pounds \section{\TeX 标志符号} \TeX \quad \LaTeX \quad \LaTeXe \par \TeX{} \quad \LaTeX{} \quad \section{引号} ` \quad ' \quad `` \quad '' \section{连字符} - \quad -- \quad --- \section{非英文字符} \oe \quad \OE \quad \ae \quad \AE \quad \aa \quad \AA \quad \o \quad \O \quad \l \quad \L \quad \ss \quad \SS \quad !` \quad ?` \section{重音字符} \`a \'a \^a \''a \~a \=a \.a \u{a} \v{a} \H{a} \r{a} \t{a} \b{a} \c{a} \d{a} \end{document}
LaTeX 中的插图
❗ 需要在导言区使用
\usepackage{graphicx}
命令
基本命令
-
正文区的使用语法
\includegraphics[<选项>]{<文件名>}
[]
中可以输入参数控制图片的缩放、旋转- 文件名的输入可以加后缀名,也可以不加
-
支持的图片格式
- EPS、PDF、PNG、JPEG、BMP
-
使用
\graphicspath{{figures/}
指定图片文件的搜索路径- 可以将图片等资源文件进行分门别类的管理
- 图片在当前目录下的 figures 目录中
-
使用
\caption
命令为图片添加说明文字 -
常使用
figure
命令渲染图片编译环境,对一个普遍进行编译,并结合浮动体使得图片在文字之后
可选参数
-
旋转角度
[angle=...]
-
缩放
[scale=...]
,在等号后输入缩放系数
-
固定值的图像高度
[height=...]
-
固定值的图像宽度
[width=...]
-
其余宽、高度控制
[height=0.1\textheight]
,表示版型文本高度 0.1 倍的图像高度[width=0.2\textwidth]
,表示版型文本宽度 0.2 倍的图像高度
❗
[]
内可以指定多个控制参数,不同参数之间用,
隔开
\documentclass{article} \usepackage{ctex} \usepackage{graphicx} \usepackage{float} \title{\heiti \LaTeX{}中的插图} \begin{document} \maketitle \LaTeX 中的图片: \begin{figure}[H] \centering \includegraphics[width=\textwidth]{图片/paintofsin.png} \caption{sin(x)的图像} \end{figure} \begin{figure}[H] \centering \includegraphics[scale=0.5,angle=45]{图片/paintoftan.PNG} \caption{tan(x)的图像} \end{figure} \end{document}
LaTeX 中的表格
❗ 使用
tabular
环境生成表格
\begin{tabular}{l c c c r} \hline & \\ \end{tabular}
‼️ 可以分别使用 l
、c
、r
表示左对齐,居中对齐,右对齐
‼️l
、c
、r
的数量代表表格的列数,中间用 |
产生表格竖线,||
产生双竖线
- 不同列之间用
&
分割,一行结束后,使用\\
换行,用\hline
产生表格横线,\hline\hline
产生双横线 - 在可选参数中,还可以使用
p{}
,输入指定列宽度,此时如果当内容超过宽度时,将会自动换行
\documentclass{article} \usepackage{ctex} \title{\heiti \LaTeX{}中的表格} \begin{document} \maketitle \LaTeX 中的表格: \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{document}
LaTeX 浮动体
❗ 在导言区使用
\usepackage{float}
命令
-
可以将图片命令放入
\figure
浮动体中\begin{figure}[H] \centering \includegraphics[width=\textwidth]{图片/paintofsin.png} \caption{sin(x)的图像} \end{figure}
‼️ 可以在环境中使用 \centering
命令是图像、表格居中
‼️ 在环境中使用 \caption
设置标题
‼️ 可以使用 \label{...}
命令设置标签
- 使用
\ref{...}
命令引用标签,从而实现交叉引用 - 可以将表格命令放入
\table
浮动体中
\begin{table}[H] \centering \begin{tabular}{|l||c|c|c|r|} \hline 姓名 &语文 &数学 &外语 &备注 \\ \hline\hline 张三 &87 &100 &93 &优秀\\ \hline 李四 &75 &64 &52 &补考另行通知\\ \hline 王五 &80 &82 &78 & \\ \hline \end{tabular} \caption{成绩单} \end{table}
-
[]
中管理浮动体的允许位置h
,此处(here),代码所在的上下文位置t
,页顶(top),代码所在页或之后页面的顶部b
,页底(bottom),代码所在页面或之后页面的底部p
,独立一页(page),浮动页面
\documentclass{article} \usepackage{ctex} \usepackage{graphicx} \usepackage{float} \title{\heiti \LaTeX{}中的浮动体} \begin{document} \maketitle \LaTeX 中的图片举例见图\ref{sin(x)交叉引用}: \begin{figure}[H] \centering \includegraphics[width=\textwidth]{图片/paintofsin.png} \caption{sin(x)的图像} \label{sin(x)交叉引用} \end{figure} \LaTeX 中的表格举例如表\ref{成绩单}所示: \begin{table}[H] \centering \begin{tabular}{|l||c|c|c|r|} \hline 姓名 &语文 &数学 &外语 &备注 \\ \hline\hline 张三 &87 &100 &93 &优秀\\ \hline 李四 &75 &64 &52 &补考另行通知\\ \hline 王五 &80 &82 &78 & \\ \hline \end{tabular} \caption{成绩单} \label{成绩单} \end{table} \end{document}
LaTeX 数学公式
❗ 需要使用
amsmath
宏包来实现对不带编号公式与矩阵的编译
❗ 需要使用
amssymb
宏包实现多行公式的编译
❗ 需要使用
mathdots
宏包引入\iddots
命令
数学公式的输入见 LaTeX 数学公式教程
-
行内公式的输入方法
$...$
\(...\)
\begin{math}...\end{math}
-
行间公式的输入方法
$$...$$
\[...\]
\begin{displaymath}...\end{displaymath}
-
自动编号公式使用
\equation
环境,在该环境中同样可以使用\lable{...}
与\ref{...}
命令实现交叉引用 -
使用不带编号的
\equation*
环境,交叉引用是使用的是小节编号
矩阵的输入方法
-
\hdotsfor{...}
实现跨列的省略号,{}
内所跨的列数 -
\multicolumn
实现混行输入 -
array
环境也可以如表格一般使用|
和\hline
添加横竖线,同时对对齐方式进行控制array
环境还可以构造更复杂的矩阵
-
可以使用
mathdots
宏包下的\iddots
命令生成反斜省略号,或自定义\adots
,自定义命令如下:newcommand{\adots}{\mathinner{\mkern2mu\raisebox{0.1em){.}\mkern2mu\raisebox{0.4em}{.}\mkern2mu\raisebox{0.7em}{.}\mkern1mu}}
多行公式
-
gather
环境可以实现多行公式,并且对每一行的公式都能进行编号 -
gather*
环境可以实现不带编号的多行公式- 或在
\gather
环境中的行末(\\
前)加入\notag
阻止编号
- 或在
-
\align
或\align*
环境实现在指定位置的对齐 -
可以使用
equation
环境下的split
环境,实现对一个公式的多行排版,同时确保整个公式块只有一个编号 -
对于类似分段函数的排版,可以使用
cases
环境- 每行公式中使用
&
分隔为两部分,通常表示值和后面的条件
- 每行公式中使用
-
\displaystyle
命令可以将行内公式显示成行间公式效果- 在文章头部添加
\everymath{\displaystyle}
命令,可以是全文实现该效果
- 在文章头部添加
\documentclass{article} \usepackage{ctex} \usepackage{amsmath} \usepackage{mathdots} \usepackage{amssymb} \title{\heiti \LaTeX{}中的数学公式} \begin{document} \maketitle \section{数学公式} \subsection{交叉引用的两种方式} \subsubsection{equation环境} Euler公式如式\ref{Euler}所示: \begin{equation} {\rm e}^{i \pi}+1=0 \label{Euler} \end{equation} \subsubsection{equation*环境} 其更一般的式子为式\ref{Euler_general}: \begin{equation*} \text e^{ix}=\cos x+i\sin x \label{Euler_general} \end{equation*} \subsection{矩阵} 可以在行内直接插入一个矩阵$ \begin{bmatrix} 1 &2\\ 3 &4 \end{bmatrix}$ ,也可以使用行内小矩阵环境 $\left( \begin{smallmatrix} 1 &2\\ 3 &4 \end{smallmatrix} \right) $ 跨列省略号: $$ \begin{bmatrix} 1 &2 &3 &4\\ \hdotsfor{4}\\ n &2n &3n &4n \end{bmatrix} $$ 混行输入 $$ \begin{bmatrix} a_{11} &a_{12} &\cdots &a_{1n}\\ &a_{22} &\cdots &a_{2n}\\ & &\ddots &\vdots\\ \multicolumn{2}{c}{\raisebox{1.3ex}[0.5pt]{\Huge 0}} & &a_{nn} \end{bmatrix} $$ array环境下的输入 $$ \begin{array}{c|c} 1 &2 \\ \hline 2 &4 \end{array} $$ 使用array环境构造更复杂的矩阵 %@{...}添加任意内容,不占表项计数 $$ \begin{array}{c@{\hspace{-5pt}}l} % 第1行,第1列 \left[ \begin{array}{ccc|ccc} a &\cdots &a &b &\cdots &b\\ &\ddots &\vdots &\vdots &\iddots\\ & &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. \rule{0mm}{7mm}\right\} p\\ \\ \left. \rule{0mm}{7mm}\right\} q \end{array} %第2行第1列 \\[-5pt] \begin{array}{cc} \underbrace{\rule{17mm}{0mm}}_m & \underbrace{\rule{17mm}{0mm}}_m \end{array} & %第2行第2列 \end{array} $$ \subsection{多行公式} \subsubsection{gather环境} \begin{gather} 3+5=5+3=8\\ 3\times 5=5 \times 3 \end{gather} \subsubsection{align环境} \begin{align} x+2y&=5\\ x^2-xy^2&=4 \end{align} \subsubsection{split环境} 区别于gather环境与align环境会对每一行都进行编号,split环境可以实现对一个公示的多行排版,并且只有一个编号 \begin{equation} \begin{split} \cos 2x &=\cos^2 x-\sin^2 x\\ &=2\cos^x -1 \end{split} \end{equation} \subsubsection{cases环境} 对于大括号下的分段函数,常常使用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}
LaTeX 中的参考文献
简单参考文献
一次管理,一次引用
❗ 使用
thebibliography
环境
\begin{thebibliography}{编号样本} \bibitem[记号]{引用标志}文献条目1 \bibitem[记号]{引用标志}文献条目2 ...... \end{thebibliography}
- 可以使用
\cite
命令在正文中引用参考文献
\documentclass{ctexart} %\usepackage{ctex} \title{\heiti \LaTeX{}中的参考文献} \begin{document} \maketitle 正文中引用参考文献\cite{book1} \begin{thebibliography}{99} \bibitem{article1}陈立辉,苏伟,蔡川,陈晓云.\emph{基于LaTeX的web数学公式提取方法研究}[J].计算机科学.2014(06) \bibitem{book1}william H.Press,Saul A.Teukolsky,William T.Vetterling,Brian P.Elannery, \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{}},BirkhAduser Boston;3 edition (June 22,2000). \end{thebibliography} \end{document}
BibTeX
一次管理,多次引用
BibLaTeX
一次管理,多次引用
LaTeX 的自定义命令与环境
自定义命令
❗
\newcommand
命令
‼️ 命令只能有字母组成,不能以 \end
开头
语法格式如下:
\newcommand<命令>[<参数个数>][<首参数默认值>]{<具体定义>}
\newcommand
可以是简单的字符串替换
\newcommand\PRC{People's Republic of \emph{China}}
\newcommand
可以使用参数
\newcommand\loves[2]{#1 喜欢 #2} \newcommand{\hatedby}[2]{#2 不受 #1 喜欢}
‼️ 参数个数最多是 9 个,使用时用 #1
、#2
、\cdots、#9
表示
\newcommand
的参数也可以有默认值
‼️ 指定参数个数的同时指定了首个参数的默认值,那么这个命令的第一个参数就成为可选的参数(要使用中括号指定)
‼️ 只能为第一个参数指定默认值,此时,第一个参数称为该命令的可选参数,在使用该命令时,如果需要为第一个参数提供实际参数,则该参数需要用 []
指定
\newcommand{\love}[3][喜欢]{#2#1#3}
\renewcommand
重新定义已有的命令
自定义环境
\newenvironment
和\renewenvironment
定义和重定义环境
语法如下
\newenvironment{<环境名称>}[<参数个数>][<首参数默认值>] {<环境前定义>} {<环境后定义>}
\documentclass{article} \usepackage{ctex} \title{\heiti \LaTeX{}中的自定义命令与环境} \newcommand\PRC{People's Republic of \emph{China}} \newcommand\loves[2]{#1 喜欢 #2} \newcommand{\hatedby}[2]{#2 不受 #1 喜欢} \newcommand{\love}[3][喜欢]{#2#1#3} \newenvironment{myabstract}[1][摘要] {\small \begin{center} \bfseries #1 \end{center} \begin{quotation}} {\end{quotation}} \begin{document} \maketitle \PRC \loves{猫}{鱼} \hatedby{猫}{萝卜} \love{猫}{鱼} \love[最爱]{猫}{鱼} \begin{myabstract} 这是一段自定义格式的摘要... \end{myabstract} \begin{myabstract}[我的摘要] 这是一段自定义格式的摘要... \end{myabstract} \end{document}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于