LaTeX编译时隐藏\label{}侧边显示框并保留公式编号
解决LaTeX中
\numberthis配合\label出现侧边方框的问题 问题描述
在align*环境中使用\numberthis为无编号公式添加编号,同时通过\label设置引用标记:
\begin{align*} \Kmat = \mathbf{V} \boldsymbol{\Lambda} \mathbf{V}^{\intercal} = \sum_{i=1}^m \lambda_i \dotprodw{\Vv_i}{\Vv_i}, \numberthis \label{kmat_eigen_decomp} \end{align*}
编译后侧边出现包含kmat_eigen_decomp的方框,但需要隐藏该方框,同时保留公式编号(如(A.18))和\label的引用功能。
原因分析
问题出在自定义样式文件style.sty中加载的showkeys包:
\RequirePackage[notref, notcite]{showkeys} % Labels in margins \renewcommand{\showkeyslabelformat}[1] { \fbox { \parbox[t]{0.6\marginparwidth} { \centering\normalfont\footnotesize\ttfamily \path{#1} } } }
这个包的作用是在文档边距显示所有\label的名称,方便编写时核对引用,而自定义的\showkeyslabelformat还给label加了方框样式。
解决方案
方案1:隐藏单个label的方框
在目标\label前添加\nokey命令,仅对当前label禁用显示:
\begin{align*} \Kmat = \mathbf{V} \boldsymbol{\Lambda} \mathbf{V}^{\intercal} = \sum_{i=1}^m \lambda_i \dotprodw{\Vv_i}{\Vv_i}, \numberthis \nokey \label{kmat_eigen_decomp} \end{align*}
方案2:全局禁用所有label的显示
如果不需要整个文档都显示label的侧边标记,直接注释或删除style.sty中以下代码:
\RequirePackage[notref, notcite]{showkeys} % Labels in margins \renewcommand{\showkeyslabelformat}[1] { \fbox { \parbox[t]{0.6\marginparwidth} { \centering\normalfont\footnotesize\ttfamily \path{#1} } } }
方案3:保留showkeys但隐藏方框
如果仍需要showkeys的其他功能,仅去掉方框样式,修改\showkeyslabelformat定义,删除\fbox包裹:
\renewcommand{\showkeyslabelformat}[1] { \parbox[t]{0.6\marginparwidth} { \centering\normalfont\footnotesize\ttfamily \path{#1} } }
或者将文本颜色设为与背景一致(如白色),彻底隐藏标记:
\renewcommand{\showkeyslabelformat}[1] { \textcolor{white}{ \parbox[t]{0.6\marginparwidth} { \centering\normalfont\footnotesize\ttfamily \path{#1} } } }
内容的提问来源于stack exchange,提问作者xiaolingxiao
相关产品推荐
相关产品推荐

