本篇文档可以搭配视频讲解使用。 讲解视频:
https://player.bilibili.com/player.html?aid=933470753&page=1
通俗易懂的Latex教程(附数学建模国赛美赛模板)
完整视频:https://www.bilibili.com/video/BV1aT4y1f74w?
这是一份面向刚入门数模,想要快速上手Latex排版的同学的Latex教学文档。 在线编辑网站overleaf:https://www.overleaf.com/ 我所使用的环境:TeX Live (自带编辑器TeXworks) 编辑器:TeXstudio
首先来看看TeX Live和TeXstudio的安装。 TeX Live安装镜像下载: https://mirrors.ustc.edu.cn/CTAN/systems/texlive/Images/ 点击下载texlive2021.iso文件
TeXstudio的安装包下载: http://texstudio.sourceforge.net/ 国外服务器下载较慢,特此放上我备份的文件链接 链接:https://pan.baidu.com/s/1Rzlij_NH5eAZ0FB1J8gKFw?pwd=8888 下载之后的安装配置可以参考博文: https://blog.csdn.net/UCB001/article/details/112546694
\documentclass{article}
\usepackage[UTF8]{ctex}
\begin{document}
文件内容
\end{document}
Latex标题层级:
一级标题
\section{一级标题内容}
二级标题
\subsection{二级标题内容}
三级标题
\subsubsection{三级标题内容}
sub:下一级
\tableofcontents
\newpage
无序列表:
\begin{itemize}
\item 第一点内容
\item 第二点内容
\item 第三点内容
\end{itemize}
有序列表:
\begin{enumerate}
\item 第一点内容
\item 第二点内容
\item 第三点内容
\end{enumerate}
字体加粗:
\textbf{加粗的字体}
斜体:
\textit{倾斜的字体}
下划线:
\underline{}
行内缩进:
\hspace{0.65em}
段内间隔:
\vspace{2ex}
需要使用两个宏包
\usepackage{float} %设置图片浮动位置的宏包
\usepackage{graphicx} %插入图片的宏包
\usepackage{subfigure} %插入多图时用子图显示的宏包
单张图片:
\begin{figure}[H]
\centering
\includegraphics[width=8cm]{../pic/p.png}% 图片相对位置
\caption{这里是图片的标题} % 图片标题
\end{figure}
多张图片(以两张图片为例):
\begin{figure}[H]
\centering
\subfigure[子图一的标题]{ % 图片1([]内为子图标题)
\includegraphics[width=0.45\textwidth]{../pic/p.png}}% 子图1的相对位置
\subfigure[子图二的标题]{ % 图片2
\includegraphics[width=0.45\textwidth]{../pic/p.png}}% 子图2的相对位置
\caption{总图标题} % 总图标题
\end{figure}
多张图片(以三张图片为例):
\begin{figure}[H]
\centering
\subfigure[子图一的标题]{ % 图片1([]内为子图标题)
\includegraphics[width=0.3\textwidth]{../pic/p.png}}% 子图1的相对位置
\subfigure[子图二的标题]{ % 图片2
\includegraphics[width=0.3\textwidth]{../pic/p.png}}% 子图2的相对位置
\subfigure[子图三的标题]{ % 图片2
\includegraphics[width=0.3\textwidth]{../pic/p.png}}% 子图3的相对位置
\caption{总图标题} % 总图标题
\end{figure}
注:图片的标题是在下面,表格的标题是在上面。
带公式标号:
\begin{equation}
\end{equation}
不带公式标号:
$$ 公式内容 $$
或者:
\[公式内容\]
公式复制神器:MathType
剪切和复制预置
公式识别神器:Mathpix
注:有时候公式中会出现加粗的字母,这时候识别的公式会报错,此时需导入宏包:
\usepackage{amsmath}
符号说明:
\begin{table}[H]
\centering
\caption{符号说明}
\begin{tabular}{cc}
\hline
\makebox[0.3\textwidth][c]{符号} & \makebox[0.4\textwidth][c]{意义} \\ \hline
$L_n$ & 经度\\ \hline
$L_a$ & 纬度 \\ \hline
\end{tabular}
\end{table}
注:c表示水平居中,l表示左对齐,r表示右对齐,|表示竖线,hline表示横线。
引入宏包:
\usepackage{threeparttable}
在end{tabular}上插入:
\begin{tablenotes}
\footnotesize
\item 注:由于篇幅有限,这里仅展示部分数据。
\end{tablenotes}
遇到可以表格过宽跳出页面的情况,可在tabular外面套一层
\resizebox{\linewidth}{!}{tabular}
使用案例:
\begin{table}[H]
\scriptsize
\caption{Table of evaluation indicators}
\resizebox{\linewidth}{!}{
\begin{tabular}{|c|c|ccc|}
\hline
\rowcolor[HTML]{DAE8FC}
Target layer & Guideline layer & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}Indicator layer} \\ \hline
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{territorial area+} & \multicolumn{1}{c|}{D1} & 0.0703 \\ \cline{3-5}
{\color[HTML]{000000} } & \multirow{-2}{*}{\begin{tabular}[c]{@{}c@{}}Natural factors\\ C1 = 0.1145\end{tabular}} & \multicolumn{1}{c|}{territorial sea area+} & \multicolumn{1}{c|}{D2} & 0.0442 \\ \cline{2-5}
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{restrictive decrees+} & \multicolumn{1}{c|}{D3} & 0.1004 \\ \cline{3-5}
{\color[HTML]{000000} } & \multirow{-2}{*}{\begin{tabular}[c]{@{}c@{}}Policy factors\\ C2 = 0.2008\end{tabular}} & \multicolumn{1}{c|}{taxation policies+} & \multicolumn{1}{c|}{D4} & 0.1004 \\ \cline{2-5}
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{investment in recycling technology+} & \multicolumn{1}{c|}{D5} & 0.1004 \\ \cline{3-5}
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{number of waste treatment plants+} & \multicolumn{1}{c|}{D6} & 0.1003 \\ \cline{3-5}
{\color[HTML]{000000} } & \multirow{-3}{*}{\begin{tabular}[c]{@{}c@{}}Economy factors\\ C3 = 0.3011\end{tabular}} & \multicolumn{1}{c|}{share of secondary and tertiary sectors(in GDP)-} & \multicolumn{1}{c|}{D7} & 0.1004 \\ \cline{2-5}
{\color[HTML]{000000} } & \begin{tabular}[c]{@{}c@{}}Population factors\\ C4 = 0.0473\end{tabular} & \multicolumn{1}{c|}{population density-} & \multicolumn{1}{c|}{D8} & 0.0473 \\ \cline{2-5}
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{plastics demand-} & \multicolumn{1}{c|}{D9} & 0.0354 \\ \cline{3-5}
{\color[HTML]{000000} } & \multirow{-2}{*}{\begin{tabular}[c]{@{}c@{}}Plastic alternatives factors\\ C5 = 0.1358\end{tabular}} & \multicolumn{1}{c|}{Cross-Price Elasticity of Demand+} & \multicolumn{1}{c|}{D10} & 0.1004 \\ \cline{2-5}
{\color[HTML]{000000} } & & \multicolumn{1}{c|}{civic education level+} & \multicolumn{1}{c|}{D11} & 0.1004 \\ \cline{3-5}
\multirow{-12}{*}{{\color[HTML]{000000} \begin{tabular}[c]{@{}c@{}}Plastic \\ \\ Waste \\ \\ Reduction\end{tabular}}} & \multirow{-2}{*}{\begin{tabular}[c]{@{}c@{}}Environmental awareness factors\\ C6 = 0.2008\end{tabular}} & \multicolumn{1}{c|}{government publicity level+} & \multicolumn{1}{c|}{D12} & 0.1004 \\ \hline
\end{tabular}}
\begin{tablenotes}
\item[1] Note: + for positive indicators (developmental indicators), - for negative indicators (restrictive indicators)
\end{tablenotes}
\end{table}
直接用网格网站添加颜色会报错,此时需导入宏包:
\usepackage[table]{xcolor}
绘制三线表可以灵活运用\toprule,\midrule两个添加线的指令
使用案例:
\begin{table}[H]
\centering
\caption{Table of properties of different plastics}
\begin{tabular}{c c c}
\toprule
\textbf{Type} & \textbf{Average life-time}(year) & \textbf{Production rate}(billion/year) \\
\midrule
PETE & 0.5 & 1.06 \\
LDPE & 2.3 & 0.94 \\
PS & 1.4 & 0.89 \\
\bottomrule
\end{tabular}
\end{table}
注:生成三线表时,可能会报错,此时需引入宏包:
\usepackage{multirow}
实用网站:
2、https://www.tablesgenerator.com/
\begin{thebibliography}{9}%宽度9
\bibitem{1} 姜启源,谢金星,叶俊.数学模型(第四版)[M].北京:高等教育出版社,2011.
\bibitem{2} 参考文献2.
\end{thebibliography}
首先设置:
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
引用:
\upcite{1}
插入格式:
$..$
符号大全: https://www.caam.rice.edu/~heinken/latex/symbols.pdf
导入两个宏包:
\usepackage{listings}
\usepackage{xcolor}
使用模块(代码内容替换成自己的内容即可):
\lstset{language=python}
\lstset{
numbers=left,
numberstyle= \tiny,
keywordstyle= \color{ blue!70},
commentstyle= \color{red!50!green!50!blue!50},
frame=shadowbox, % 阴影效果
rulesepcolor= \color{ red!20!green!20!blue!20} ,
escapeinside=``, % 英文分号中可写入中文
breaklines=true,
xleftmargin=2em, aboveskip=1em,
framexleftmargin=2em
}
\noindent 对sonar数据集分类的代码如下:
\begin{lstlisting}
代码内容
\end{lstlisting}
注,若代码中有中文注释,需作如下调整: 在菜单栏中的“选项”,进行下图设置
latex默认的页面较窄,通过下面的代码能将页面设置成A4纸大小。
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
Texstudio快捷键
多行注释:Ctrl+T
多行解注释::Ctrl+U
模板可在群文件中进行下载。使用详情见视频。
交流群:710413249
下面整理了一些群友常问的问题,这里做一个统一回答和记录。
选项->设置TeXstudio
这个报错的意思是找不到cumcmthesis.cls这个文件,这个文件是配置文件,里面设置了各章节的结构/类型,使用模板需保证其在和.tex的同文件夹下。
有的比赛规定摘要页不包括页码,从正文第一页开始标号。
这里可以在\begin{abstract}
下方添加命令
\thispagestyle{empty}
这个命令表示清空当前页的页码号 然后再在正文第一页的section中添加命令
\setcounter{page}{1}
这个命令表示页码从当前页从1开始重新计数
希望群友能踊跃提问,群内已开匿名功能,如果不好意思提问,可以匿名提问,正是在提出问题和解决问题的过程中,这篇文档能够得以更加丰富。