LaTeX数学模式&上下标&代码块

效果就是如上图所示了。学习了使用数学模式插入公式和使用上标和公式的编号。这里的目录没有展开,在编译一次目录会展开,代码块会被挤到下一页上面去。

\documentclass[UTF8]{ctexart}
\title{练习使用LaTeX的数学公式}
\author{NianHao}
\date{\today}
%引入数学功能
\usepackage{amsmath}
%引入代码块
\usepackage{listings}
\usepackage{fontspec}
\usepackage{xcolor}
%\setmonofont{Consolas}
%设置代码块格式

\definecolor{CPPGray}{RGB}{211,211,211}
\lstset{
 columns=fixed,       
 numbers=left,   % 在左侧显示行号
 numberstyle=\tiny\color{gray},% 设定行号格式
 frame=shadowbox,%none,% 不显示背景边框
 %aboveskip=1em,
 backgroundcolor=\color[RGB]{211,211,211},% 设定背景颜色
 keywordstyle=\color[RGB]{40,40,255},% 设定关键字颜色
 numberstyle=\footnotesize\color{darkgray},           
 commentstyle=\it\color[RGB]{0,96,96},% 设置代码注释的格式
 stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},% 设置字符串格式
 showstringspaces=true,% 不显示字符串中的空格
 %language=c++, % 设置语言
}
\begin{document}
\maketitle
\tableofcontents
\section{数学模式}
LaTeX的数学模式有两种:行内模式(inline)和行间模式(display).前者在正文中插入数学公式;后者独立排列单独成行,并且是自动居中的。

在行文中,使用\$...\$可以插入行内公式。使用\textbackslash [...\textbackslash ]插入行间公式。如果需要对公式进行编号,可以使用equation环境:
\begin{lstlisting}
\begin{equation}
...
\end{equation}
\end{lstlisting}
\section{上下标}
\begin{lstlisting}
Einstein 's $E=mc^2$.

\[ E=mc^2. \]

\begin{equation}
E=mc^2.
\end{equation}
\end{lstlisting}
Einstein 's $E=mc^2$.

\[ E=mc^2. \]

\begin{equation}
E=mc^2.
\end{equation}
\end{document}
View Code

要注意的是,使用颜色,必须引入

\usepackage{xcolor}

这个包不引入的话,无法解析颜色。另外,设置颜色,也可以直接设置RGB的值,也可以先定义一个颜色名字。看需要吧。

猜你喜欢

转载自www.cnblogs.com/superxuezhazha/p/10690062.html