大家好,欢迎来到IT知识分享网。
LeTaX入门教学
LaTeX
安装LaTeX
参考文章https://zhuanlan.zhihu.com/p/
LaTeX基本结构
在LaTeX中主要分文导言区和正文区
%导言区 \documentclass{article} %正文区 \begin{document} hello world! \end{document}
documentclass 后面的类可以为 article/book/report/letter 。在 导言区 设置全局变量。在 正文区 进行文本的编写,在LaTeX中,上述 documentclass 的类适用于英文文本。中英混排在后续进行讲解。一个LaTeX中只能有一个document, begin 和 end 必须成对使用,其后续接着的环境名为 document 。
% 引入注释,在编译时不会进行编译。
%导言区 \documentclass{article} \title{Hello LaTeX} \author{kiukiu} \date{\today} %正文区 \begin{document} \maketitle hello world! \end{document}
\title{Hello LaTeX} \author{kiukiu} \date{\today}
上述代码分别表示标题、作者和日期, \today 显示编写当天日期。
!!!!以上内容均不涉及中文文本内容!!!!
若文本中包含数学公式则使用 &数学文本& 来进行编写,下文会更加详细的对数学公式的编写进行讲解。
%导言区 \documentclass{article} \title{Hello LaTeX} \author{kiukiu} \date{\today} %正文区 \begin{document} \maketitle we set a function $f(x)=2*x+3$ . \end{document}
LaTeX中文结构
若文本内容包含中文时,需要将编译器设置为 XeLaTeX ,默认字体编码为 UTF-8 。将 document 的类变为 ctexart/ctexbook/ctexrep ,不存在中文版 letter 的中文类。另一种方式是增加 \usepackage{ctex}。
%导言区 \documentclass{ctexart} \title{你好, LaTeX} \author{邱邱} \date{\today} %正文区 \begin{document} \maketitle 你好,LaTeX. \end{document}
%导言区 \documentclass{article} \usepackage{ctex} \title{你好, LaTeX} \author{邱邱} \date{\today} %正文区 \begin{document} \maketitle 你好,LaTeX. \end{document}
LaTeX字体字号设置
字体包含:字体编码、字体族、字体系列、字体形状和字体大小五个内容
- 字体编码:分为正文和数学编码,上述内容已经陈述,不再赘述
- 字体族:罗马字体、无衬线字体和打字机字体
表达的方式有两种,按照上述顺序进行编写
\textrm{Roman Family} {\rmfamily Roman Family } \textsf{Sans Serif Family} {\sffamily Sans Serif Family} \texttt{Typewriter Family} {\ttfamily Typewriter Family}
上述两种表示方式中,第一种是字体命令,第二种是字体声明,均可用于修改字体族。
- 字体系列:粗细和宽度两种
\textmd{粗细} {\mdseries 粗细} \textbf{宽度} {\bfseries 宽度}
- 字体形状:直立体 斜体 伪斜体 小型大写
\textup{ 直立体} \textit{ 斜体} \textsl{伪斜体} \textsc{小型大写Minmax } {\upshape 直立体} {\itshape 斜体} {\slshape 伪斜体} {\scshape 小型大写Minmax}
- 字体大小:
{\tiny LaTeX} {\scriptsize LaTeX} {\footnotesize LaTeX} {\small LaTeX} {\normalsize LaTeX} {\large LaTeX} {\Large LaTeX} {\LARGE LaTeX} {\huge LaTeX} {\Huge LaTeX}
字体的大小是根据 normalsize 的大小来定义,并调整其相对大小的。可以在 documentclass 中定义初始字体的大小,例如 \documentclass[10pt]{ctexart} 将初始字体设为10磅, 初始字体只能设置为10-12磅 。
中文字体:
{\songti 宋体} {\heiti 黑体} {\fangsong 仿宋} {\kaishu 楷书}
中文字体大小:
\zihao {5} 中文字体大小 %五号字体 \zihao {-0} 中文字体大小 %小初号字体
字体大小中 { } 里的数值表示字体大小,带负号的是 小某号 。
具体字号详情使用 cmd 查看 texdoc ctex 。
不建议在文本中大量使用大量命令,建议使用 \newcommand 命令定义一个新的命令以执行相关操作。(在导言区声明、在正文区调用)
%导言区 \documentclass{article} \newcommand{\myfont}{\textbf{\textit{\textsf{Newcommand Test}}}} %正文区 \begin{document} \myfont \end{document}
LaTeX文章结构
\section{LaTeX} LaTeX是一款文档编辑软件。 \subsection{安装} 可以参考博客xxx \subsubsection{下载} 打开官方网站xxxx
段落用 空行 或 \par 来实现,\ 能实现换行,但没有产生新的段落。
在上述 节 的用法中,在其内部加入正文内容,且不受 节 命令的影响。
使用 ctexart 时 scetion 标题时集中排版的,但这些格式时可以通过 \ctexset 进行修改,详情参考 ctex 宏包手册( texdoc ctex )。
通过 \tableofcontents 自动生成目录。
\charpte { xxx} 会产生带章节的标题,但在 article 内不存在,可用于 book 。同时 subsubsection 不起作用。
特殊字符
- 空格
在英文文本的编写时,在英文字母间插入多个空格,编译后也只能显示一个空格;而在汉语中出现一个或多个空格,编译后都不显示;中英混排时会自动在中英交界处生成一个空格。若需要产生指定空格可以使用
好好学习\quad 天天向上 %产生1em的空格 好好学习\uad 天天向上 %产生2em的空格 好好学习\enspace 天天向上 %产生0.5em的空格 好好学习\, 天天向上 %产生1/6em的空格 好好学习\thinspace 天天向上 %产生1/6em的空格 好好学习\ 天天向上 %产生1个的空格 好好学习~天天向上 %产生硬空格,不可分割的空格 好好学习\kern 1pc 天天向上 %产生1pc的空格,可以为负数 好好学习\hspace{35pt} 天天向上 %产生35pt的空格 好好学习\hphantom{xyz} 天天向上 %产生xyz所产生长度的空格 好好学习\hfill 天天向上 %产生弹性长度的空格
- 控制符
\# \{ \} \$ \~ {q} \_ {q} \% \^ {q} \textbackslash
- 特殊符号
\S \P \dag \ddag \copyright \pounds
- 标识符号
\TeX{} \LaTeX{} \LaTeXe{}
- 引号
单双引号的前引号均用上点来表示 ` “ ,而后引号则正常表示即可。
- 连字符
分别用 – 、 – 、 — 来表示3个不同长度的连字符。 - 非英文字符
\oe \OE \ae \` \AE \aa \AA ?` \o \O \l \L \ss \SS
- 重音符号
\`o \'o \^o \' 'o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \b{o} \c{o} \d{o}
表格或图片的插入和引用
在插入表格或图片时,需要在导言区加入宏包 \usepackage{graphicx} 和图像搜索路径 \graphicspath{
{path/}} 。
\usepackage{graphicx} \graphicspath{
{figure/}} \begin{figure}[htbp] \centering \includegraphics[scale=0.3]{1.png} \caption{test} \end{figure}
[htbp] 分别表示此处、页顶、底页、独立一页。
\centering 表示图片剧中排版
\caption{test} 显示图片标题且自动编号
[scale=0.3] 的参数可以为空,也可以按需修改 height/weight/angle ,需要多个参数时可用逗号进行连接。
表格的用法与图片类似。
%导言区 \documentclass{ctexart} \usepackage{graphicx} \graphicspath{
{figure/}} \title{你好, LaTeX} \author{邱邱} \date{\today} %正文区 \begin{document} \maketitle 引用\ref{xx}%引用标签 \begin{table} \centering \caption{test}\label{xx}&设定标签 \begin{tabular}{l||c |c| c |r} %l左对齐,c居中,r右对齐 \hline 姓名 & 数学 & 语文 & 英语&备注\\ \hline\hline x&100&98&89& \\ \hline s&96&85&80&\\ \hline%加横线 \end{tabular} \end{table} \end{document}
数学公式的插入和引用
%%行内公式 $f(x)=2*x+1$ \(f(x)=2*x+1\) \begin{math} f(x)=2*x+1 \end{math} %%行间公式 $$f(x)=2*x+1$$ \[f(x)=2*x+1\] \begin{displaymath} f(x)=2*x+1 \end{displaymath}
%%上标 \begin{displaymath} f(x)=x^2+1 \end{displaymath} \begin{displaymath} f(x)=x^20+1 \end{displaymath} \begin{displaymath} f(x)=x^{20}+1 \end{displaymath} %%下标 \begin{displaymath} f(x)=x_2+1 \end{displaymath} \begin{displaymath} f(x)=x_20+1 \end{displaymath} \begin{displaymath} f(x)=x_{20}+1 \end{displaymath}
上下标分别用 ^ _ 来表示,若上标数值或关系式长度大于1则需要通过添加 { } 来将其内容包含在一起,否则会出现图片公式2和公式5所示错误。
%%希腊字母 $\alpha$ $\beta$ $\gamma$ $\epsilon$ $\pi$ $\omega$ $\Gamma$ $\Delta$ $\Theta$ $\Pi$ $\Omega$\\ $\alpha^3+\beta^2+\gamma=0$\\ %%数学函数 $\log $ $\sin $ $\cos $ $\arcsin $ $\arccos )$ $\ln$\\ $\sqrt{4}$ $\sqrt[3]{4}$ \\ $\sin^2 x+\cos^2 x=1$
%%分式 $3/4$ $\frac{3}{4}$ $3/42$ $\frac34$ $\frac342$
注意观察 \frac 的用法,不加花括号时只能区分单个字母。
引用\ref{eq1} %%对公式进行编号并引用 \begin{equation} a+b=b+a \label{eq1} \end{equation}
%%引入宏包 \usepackage{amsmath} %%不对公式进行编号 \begin{equation*} a+b=b+a \end{equation*}
- 公式矩阵
\[ \begin{matrix} 1 & 2 \\ 2 & 1 \end{matrix} \] \[ \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} \] \[ \begin{bmatrix} 1 & 2 \\ 2 & 1 \end{bmatrix} \] \[ \begin{Bmatrix} 1 & 2 \\ 2 & 1 \end{Bmatrix} \] \[ \begin{vmatrix} 1 & 2 \\ 2 & 1 \end{vmatrix} \] \[ \begin{Vmatrix} 1 & 2 \\ 2 & 1 \end{Vmatrix} \]
\[ A=\begin{bmatrix} a_{11}& \dots &a_{1n}\\ & \ddots & \vdots\\ 0 & & a_{nn} \end{bmatrix}_{n \times n} \]
分块矩阵:一个矩阵作为另一个矩阵的元素来处理
在矩阵内容中可以通过 \text{\Large 0} 来临时切换内容为文本。
%%三角矩阵 \[ A=\begin{bmatrix} a_{11}& a_{12}&\cdots &a_{1n}\\ & a_{22}&\cdots&a_{2n}\\ & &\ddots & \vdots\\ \multicolumn{2}{c}{\raisebox{1.3ex}[0pt]{\Huge 0}}& &a{nn} \end{bmatrix}_{n \times n} \]
\usepackage{amsmath} \usepackage{amssymb} %%跨列省略号:\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} \frac 12 & 0 \\ \hline 0 & -\frac abc \\ \end{array} \]
%gather和gather*环境 \begin{gather} a+b=b+a\\ ab=ba \end{gather} \begin{gather*} c+d=d+c\\ cd=dc \end{gather*} %在\\前使用\notag阻止编号 \begin{gather} a+b=b+a \notag\\ ab=ba \end{gather} %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}
文献插入与引用
文献插入参考知乎文章
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/122069.html