出现了一个有关“amsmath”宏包的错误:“Package amsmath Error: Multiple \label's”这是为什么。

2020-07-10 16:10发布

## 编译环境 操作系统 * [x ] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x ] TexLive ...

## 编译环境 操作系统 * [x ] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x ] TexLive `2020` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 各位老师同学们大家好!我是一个学生,最近在学习研究LaTeX,我之前在网上找了一个博士论文模板,然后我自己在读别人写的代码。但是最近在模板里加东西的时候遇到了一个问题,主要内容是在某一个章节中我写了这样一段代码: ``` \begin{equation} \frac{\partial u}{\partial x} + \frac{\partial v}{\partial y} + \frac{\partial w}{\partial z} = 0 \label{eq:singlemass} \end{equation} 对于常用的不可压、忽略体力的N-S方程以及连续性方程可以表示为\eqref{eq:singlemass} \begin{align} \frac{\partial \mathbf{u}}{\partial t} + \left( \mathbf{u} \cdot \nabla \right) \mathbf{u} &= -\frac{1}{\rho} \nabla p + \nu \nabla^2 \mathbf{u} \label{eq:testNS} \\ \nabla \cdot \mathbf{u} &= 0 \label{eq:testMass} \end{align} 式\eqref{eq:testNS}和式\eqref{eq:testMass}是最常见的不可压N-S方程及质量方程。式\eqref{eq:singlemass}是质量方程。 ``` 然后总是报错为: ``` Package amsmath Error: Multiple \label's: label 'eq:singlemass' will be lost. \end{align} ``` 我一开始一直不知道是怎么回事,后来发现把amsmath宏包注释掉之后,就没有这个问题了,但是按道理注释掉amsmath宏包不是无法使用align这些环境的嘛?见下图: align已经变红了,但是这个最后还能编译出来,我不知道这是为什么。 后来我发现我加上amsmath宏包,align红色会消失,但是这个位置必须在这个论文模板的“setting”之后,如果在它之前加又会出现前面那个错误。 所以综上,我的**问题**是: 1. 出现该错误是什么原因? 2. amsmath宏包和模板的“setting”有什么矛盾之处或者相关联之处?导致不加数学宏包也可以编译公式、在其之前加又出现错误、在其之后加又恢复正常。 非常感谢大家的指导与帮助!最后附带该模版的setting文件。 ## 模板setting文件 ``` %---------------------------------纸张大小设置---------------------------------% \usepackage{geometry} % 普通A4格式缩进 \geometry{left=2.5cm,right=2.5cm,top=2.54cm,bottom=2.54cm} % 论文标准缩进 %\geometry{left=1.18in,right=1.18in,top=0.98in,bottom=0.98in} %------------------------------------------------------------------------------% %----------------------------------必要库支持----------------------------------% %\usepackage{bm} % 用来加粗希腊字母 \usepackage{xcolor} \usepackage{tikz} \usepackage{layouts} \usepackage[numbers,sort&compress]{natbib} \usepackage{clrscode} \usepackage{gensymb} \usepackage[final]{pdfpages} \usepackage{setspace} %调整行间距 \usepackage{ragged2e} \usepackage{emptypage} % cleardoublepage后变为空白页 %------------------------------------------------------------------------------% %--------------------------------设置标题与目录--------------------------------% \usepackage[sf]{titlesec} \usepackage{titletoc} %------------------------------------------------------------------------------% %--------------------------------添加书签超链接--------------------------------% \usepackage[unicode=true,colorlinks=false,pdfborder={0 0 0}]{hyperref} % 在此处修改打开文件操作 \hypersetup{ bookmarks=true, % show bookmarks bar? pdftoolbar=true, % show Acrobat’s toolbar? pdfmenubar=true, % show Acrobat’s menu? pdffitwindow=true, % window fit to page when opened pdfstartview={FitH}, % fits the width of the page to the window pdfnewwindow=true, % links in new PDF window } % 在此处添加文章基础信息 \hypersetup{ pdftitle={title}, pdfauthor={author}, pdfsubject={subject}, pdfcreator={creator}, pdfproducer={producer}, pdfkeywords={key1 key2 key3} } %------------------------------------------------------------------------------% %---------------------------------设置字体大小---------------------------------% \usepackage{type1cm} %里面是阿拉伯数字1 % 字号与行距,统一前缀s(a.k.a size) \newcommand{\sChuhao}{\fontsize{42pt}{63pt}\selectfont} % 初号, 1.5倍 \newcommand{\sYihao}{\fontsize{26pt}{39pt}\selectfont} % 一号, 1.5倍 \newcommand{\sErhao}{\fontsize{22pt}{28pt}\selectfont} % 二号, 1.25倍 \newcommand{\sXiaoer}{\fontsize{18pt}{18pt}\selectfont} % 小二, 单倍 \newcommand{\sSanhao}{\fontsize{16pt}{24pt}\selectfont} % 三号, 1.5倍 \newcommand{\sXiaosan}{\fontsize{15pt}{22pt}\selectfont} % 小三, 1.5倍 \newcommand{\sSihao}{\fontsize{14pt}{21pt}\selectfont} % 四号, 1.5倍 \newcommand{\sLargeHalfXiaosi}{\fontsize{13pt}{19pt}\selectfont} % 半小四, 1.5倍 \newcommand{\sHalfXiaosi}{\fontsize{12.5pt}{16.25pt}\selectfont} % 半小四, 1.25倍 \newcommand{\sRealHalfXiaosi}{\fontsize{12.5pt}{13pt}\selectfont} % 半小四, 约1倍 \newcommand{\sXiaosi}{\fontsize{12pt}{14.4pt}\selectfont} % 小四, 1.25倍 \newcommand{\sLargeWuhao}{\fontsize{11pt}{11pt}\selectfont} % 大五, 单倍 \newcommand{\sWuhao}{\fontsize{10.5pt}{10.5pt}\selectfont} % 五号, 单倍 \newcommand{\sXiaowu}{\fontsize{9pt}{9pt}\selectfont} % 小五, 单倍 \newcommand{\sNormalParagraph}{\fontsize{12pt}{20pt}\selectfont} %------------------------------------------------------------------------------% %---------------------------------设置中文字体---------------------------------% \usepackage{fontspec} % 访问微软系统字体 \usepackage[SlantFont,BoldFont,CJKchecksingle]{xeCJK} %底层的一个包,ctex包是一个直接可以用的 \usepackage{CJKnumb} % 调用微软默认字体并改名 \newcommand\defaultSog{SimSun} \newcommand\defaultHei{SimHei} \newcommand\defaultKai{KaiTi} \newcommand\defaultFag{FangSong} \newcommand\defaultEngFont{Times New Roman} \newcommand\codeFont{Consolas} % 设置字体族,每个字体族在这里有三种形状:主字体、无衬线字体、打字机字体 \defaultfontfeatures{Mapping=tex-text} % 算是一个固定格式吧 \setCJKmainfont[ItalicFont=\defaultKai, BoldFont=\defaultHei]{\defaultSog} %设置主中文字体族及对应斜体和粗体 \setCJKsansfont[ItalicFont=\defaultKai, BoldFont=\defaultHei]{\defaultSog} %设置无衬线中文字体族及对应斜体和粗体 \setCJKmonofont{\codeFont} %设置打字机中文字体族,多用于代码 \setmonofont{\codeFont} %设置打字机字体族(英文) \setmainfont{\defaultEngFont} %设置主字体族(英文) \setsansfont{\defaultHei} %设置无衬线字体族(英文)为黑体 % 扩充中文字体族 \setCJKfamilyfont{song}{\defaultSog} % 宋体 默认 \setCJKfamilyfont{hei}{\defaultHei} % 黑体 \setCJKfamilyfont{kai}{\defaultKai} % 楷体 \setCJKfamilyfont{fang}{\defaultFag} % 仿宋体 \setCJKfamilyfont{tnr}{\defaultEngFont} % 用于页眉学校名,特殊字体,powerby https://github.com/ecomfe/fonteditor \setCJKfamilyfont{nwpu}{nwpuname} % 新建字体命令,统一前缀f(a.k.a font) \newcommand{\fSong}{\CJKfamily{song}} \newcommand{\fHei}{\CJKfamily{hei}} \newcommand{\fFang}{\CJKfamily{fang}} \newcommand{\fKai}{\CJKfamily{kai}} \newcommand{\fNWPU}{\CJKfamily{nwpu}} \newcommand{\fTNR}{\CJKfamily{tnr}} %------------------------------------------------------------------------------% %------------------------------添加插图与表格控制------------------------------% \usepackage{graphicx} \usepackage{float} \usepackage[font=normalsize,labelsep=quad]{caption} \usepackage{subfigure} \usepackage{wrapfig} \usepackage{multirow,makecell} \usepackage{longtable} \usepackage{booktabs} \usepackage{tabularx} \usepackage{setspace} \usepackage{array} %设置标题为五号 \DeclareCaptionFont{cWuhao}{\sWuhao} %\DeclareCaptionFont{cWuhao}{\fontsize{10.5pt}{20pt}\selectfont} \captionsetup[table]{labelfont=cWuhao,textfont=cWuhao} \captionsetup[figure]{labelfont=cWuhao,textfont=cWuhao} %\setlength{\belowcaptionskip}{-5pt} %调整图片标题与下文距离 %设置表格的列格式 \newcolumntype{C}{>{\centering\arraybackslash}X} % 居中等宽 %设置表格默认字号为五号 \let\oldtabularx\tabularx \renewcommand{\tabularx}{\sWuhao\oldtabularx} \let\oldtabular\tabular \renewcommand{\tabular}{\sWuhao\oldtabular} %------------------------------------------------------------------------------% %---------------------------------添加列表控制---------------------------------% \usepackage{enumerate} \usepackage{enumitem} %------------------------------------------------------------------------------% %---------------------------------设置引用格式---------------------------------% \renewcommand\figureautorefname{图} % 自动引用格式:\autoref \renewcommand\tableautorefname{表} \renewcommand\equationautorefname{式} \newcommand\myreference[1]{[\ref{#1}]} %\newcommand\eqrefe[1]{式(\ref{#1})} % 增加 \ucite 命令使显示的引用为上标形式 \newcommand{\ucite}[1]{$^{\mbox{\scriptsize \cite{#1}}}$} \renewcommand\arraystretch{1.4} % 引用公式、图片(子图)、表格时附带章节,并以短横线-连接 %\numberwithin{equation}{chapter} %\numberwithin{figure}{chapter} %\numberwithin{table}{chapter} \renewcommand{\theequation}{\thechapter-\arabic{equation}} \renewcommand{\thefigure}{\thechapter-\arabic{figure}} \renewcommand{\thesubfigure}{\thechapter-\arabic{figure} (\alph{subfigure})} \renewcommand{\thetable}{\thechapter-\arabic{table}} %------------------------------------------------------------------------------% %--------------------------------设置定理类环境--------------------------------% \usepackage[amsthm,thmmarks]{ntheorem} \newtheorem{myexample}{例} \newtheorem{thm}{定理} \newtheorem{theorem}{\hspace{2em}定理}[chapter] \newtheorem{assumption}{\hspace{2em}假设}[chapter] % 允许公式换页 %\allowdisplaybreaks[4] %------------------------------------------------------------------------------% %--------------------------设置中文段落缩进与正文版式--------------------------% \XeTeXlinebreaklocale "zh" % 使用中文的换行风格 \XeTeXlinebreakskip = 0pt plus 1pt % 调整换行逻辑的弹性大小 \usepackage{indentfirst} % 段首空格设置 \setlength{\parindent}{24.7pt} % 段首空格长度,略大于两个小四汉字 \setlength{\parskip}{2pt plus 2pt minus 1pt} % 段落间距,否则一级标题故障 %\setlength{\parskip}{3pt plus 1pt minus 1pt} \renewcommand{\baselinestretch}{1} % 行距,对应1.5倍行距 %------------------------------------------------------------------------------% %----------------------------设置段落标题与目录格式----------------------------% \setcounter{secnumdepth}{3} % 计数到三级 \setcounter{tocdepth}{2} %\newcommand\chapterID[1]{第\CJKnumber{#1}章} \renewcommand{\chaptername}{\thechapter~~} % 章的标签 \renewcommand{\figurename}{图} \renewcommand{\tablename}{表} \renewcommand{\bibname}{参考文献} \renewcommand{\contentsname}{目~~~~录} \newcommand{\keywords}[1]{\\ \\ \textbf{关~键~词}:#1} % 其实后面并没有用到 % 设置各级标题的样式 \titleformat{\chapter}[block]{\fontsize{16pt}{20pt}\selectfont \filcenter \fHei} {\sffamily\arabic{chapter}}{1em}{}[]% hang表示默认值,悬挂标签;第三个大括号表示格式;第四个大括号表示标签样式;第五个表示水平距离 \titleformat{\section}[hang]{\fHei \fontsize{14pt}{20pt}\selectfont}% {\sffamily\arabic{chapter}.\arabic{section}}{0.5em}{}[] \titleformat{\subsection}[hang]{\fHei\fontsize{12pt}{20pt}\selectfont}% {\sffamily\arabic{chapter}.\arabic{section}.\arabic{subsection}}{0.5em}{}[] \titleformat{\subsubsection}[hang]{\fHei\fontsize{12pt}{20pt}\selectfont}% {\sffamily(\arabic{subsubsection})}{0.5em}{}[] % 小标题式的subsubsection:(4) 标题 % 设置正文中各级标题之间的缩进 \titlespacing{\chapter}{0pt}{-2.5ex plus .1ex minus .2ex}{2ex} %\titlespacing{\chapter}{0pt}{0pt}{0pt} %\titlespacing{\chapter}{0pt}{-3ex plus .1ex minus .2ex}{0.25em} \titlespacing{\section}{0pt}{9pt}{0pt} \titlespacing{\subsection}{0pt}{6pt}{0pt} \titlespacing{\subsubsection}{10pt}{5pt}{0pt} % 定义目录中各级标题之间的格式以及缩进 \titlecontents{chapter}[0pt] {\fSong \fontsize{12pt}{20pt}\selectfont }% {\contentsmargin{0pt}\fSong\makebox[0pt][l]{\thecontentslabel}\hspace{1.5em}}% {\contentsmargin{0pt}\fSong}% {\titlerule*{.}\contentspage}[\vspace{0em}] %{\titlerule*[.5pc]{.}\contentspage}[\vspace{0em}] \titlecontents{section}[12mm] %标签距离页面左边距 {\fontsize{12pt}{20pt}\selectfont \fSong}{\contentslabel{1.8em}}%标签距离目录内容距离 {}{\titlerule*{.}\contentspage} \titlecontents{subsection}[20mm]%标签距离页面左边距 {\fontsize{12pt}{20pt}\selectfont \fSong}{\contentslabel{2.5em}} %标签距离目录内容距离 {}{\titlerule*{.}\contentspage} \titlecontents{subsubsection}[28mm]%标签距离页面左边距 {\fontsize{12pt}{20pt}\selectfont \fSong}{\contentslabel{3em}} %标签距离目录内容距离 {}{\titlerule*{.}\contentspage} %------------------------------------------------------------------------------% %---------------------------------设置页眉页脚---------------------------------% \usepackage{fancyhdr} \usepackage{fancyref} % 引用时带上页码 %\addtolength{\headsep}{-0.2cm} %页眉位置 %\addtolength{\footskip}{-0.1cm} %页脚位置 \setlength{\headsep}{0.41cm} %页眉位置 \setlength{\footskip}{0.79cm} %页脚位置 %\addtolength{\topmargin}{0.5cm} %页眉到页边距离? % 设置双划线:文武线 \newcommand{\makeheadrule}{% \makebox[0pt][l]{\rule[0.6\baselineskip]{\headwidth}{0.4pt}}% \rule[0.68\baselineskip]{\headwidth}{1.96pt}} \makeatletter \renewcommand{\headrule}{% {\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi\makeheadrule}} \makeatother \pagestyle{fancyplain} \fancyhf{} % 先清除所有页眉页脚 % 页脚 \cfoot{\fontsize{9pt}{11pt}\selectfont \thepage} \renewcommand{\chaptermark}[1]{\markboth{\thechapter~~ #1}{}} % 页眉 \fancyhead[CE]{\fontsize{9pt}{11pt}\selectfont 西北工业大学博士学位论文} % 偶数页 \fancyhead[CO]{\fontsize{9pt}{11pt}\selectfont \leftmark} % 奇数页,在此leftmark指章标题 % % % %------------------------------------------------------------------------------% %----------------------------------其他补充设置--------------------------------% % 重置列表环境的间隔 % \let\orig@Itemize =\itemize % \let\orig@Enumerate =\enumerate % \let\orig@Description =\description % \def\Myspacing{ % \itemsep=1.5ex \topsep=-0.5ex \partopsep=0pt \parskip=0pt \parsep=0.5ex % } % \def\newitemsep{ % \renewenvironment{itemize}{\orig@Itemize\Myspacing}{\endlist} % \renewenvironment{enumerate}{\orig@Enumerate\Myspacing}{\endlist} % \renewenvironment{description}{\orig@Description\Myspacing}{\endlist} % } % \def\olditemsep{ % \renewenvironment{itemize}{\orig@Itemize}{\endlist} % \renewenvironment{enumerate}{\orig@Enumerate}{\endlist} % \renewenvironment{description}{\orig@Description}{\endlist} % } % \newitemsep % 下划线 \makeatletter \newcommand\dlmu@underline[2][5cm]% {\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt} \let\coverunderline\dlmu@underline \makeatother %------------------------------------------------------------------------------% %----------------------------------添加代码控制--------------------------------% \usepackage{listings} \newfontfamily\courier{Courier New} \lstset{linewidth=1.1\textwidth, numbers=left, %设置行号位置 basicstyle=\small\courier, numberstyle=\tiny\courier, %设置行号大小 keywordstyle=\color{blue}\courier, %设置关键字颜色 %identifierstyle=\bf, commentstyle=\it\color[cmyk]{1,0,1,0}\courier, %设置注释颜色 stringstyle=\it\color[RGB]{128,0,0}\courier, %framexleftmargin=10mm, frame=single, %设置边框格式 backgroundcolor=\color[RGB]{245,245,244}, escapeinside=``, %逃逸字符(1左面的键),用于显示中文 breaklines, %自动折行 extendedchars=false, %解决代码跨页时,章节标题,页眉等汉字不显示的问题 xleftmargin=2em,xrightmargin=2cm, aboveskip=1em, %设置边距 tabsize=4, %设置tab空格数 showspaces=false %不显示空格 basicstyle=\small\courier } \renewcommand{\lstlistingname}{CODE} \lstloadlanguages{% Check Dokumentation for further languages, page 12 Pascal, C++, Java, Ruby, Python, Matlab, R, Haskell } %------------------------------------------------------------------------------% %---------------------------------设置词汇总表---------------------------------% \usepackage[acronym]{glossaries} \makeglossaries \loadglsentries{glossaries} %------------------------------------------------------------------------------% \endinput % 这是简单的 thesis(book) 的导言区设置,不能多带带编译。 ```