我只是想用以下内容突出显示小节的标题:

\subsection{\hl{Computation Time}} \label{sec:comp_time}

我在 latex 文件的开头添加了“\usepackage{soul}”。

但是我收到一条错误消息,提示“\let 的参数有一个额外的 }”

我也尝试过使用

\subsection{\hl{Computation Time}\label{sec:comp_time}}

(不确定哪种方法是正确的)但仍然出现相同的错误

非常抱歉,但我在文件开头确实添加了混乱的软件包序言等

\documentclass[12pt]{spieman}  % 12pt font required by SPIE;

\usepackage[left, pagewise]{lineno}
\linenumbers

\usepackage{multicol}
\usepackage[utf8]{inputenc} %unicode support
\usepackage{amssymb}
\setlength{\textfloatsep}{0.7cm}
\usepackage{graphicx}
\usepackage{float}
\restylefloat{table}
\usepackage{placeins}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{array}
\usepackage{color}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{subfig}
 \usepackage[strict]{changepage}
\usepackage[skip=0pt]{caption}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{shapes,fit} %use shapes library if you need ellipse

\usetikzlibrary{shapes,arrows}
\usepackage{graphicx}

\usepackage{lipsum}
\usepackage{amsfonts,booktabs,multirow,array,comment}
\usepackage{footnote}
\usepackage{gensymb}
\usepackage{color}
\renewcommand*{\arraystretch}{4}
\usepackage{graphbox} 
\newcommand*{\myinclude}[1]{\includegraphics[width=1in, align=m]{#1}}
\interdisplaylinepenalty=2500
\newcommand{\cmt}[1]{{\textcolor{red}{(\emph{#1})}}}
\newcommand{\M}[1]{\boldsymbol{#1}}
\newcommand{\V}[1]{\boldsymbol{#1}}
\DeclareMathOperator*{\argmax}{argmax}

\newcommand*{\bigCI}{%
  \mathrel{\text{%
    {\rotatebox[origin=c]{90}{\resizebox{2.25ex}{1.65ex}{$\vDash$}}}%
  }}%
}
\usepackage{color}
\usepackage{mathtools}
\usepackage{textcomp}
\sloppy
\definecolor{lightgray}{gray}{0.5}

\setlength{\parindent}{0pt}
\newcommand{\forceindent}{\leavevmode{\parindent=1.5em\indent}}
\DeclareRobustCommand{\orderof}{\ensuremath{\mathcal{O}}}
\makeatletter

\makeatother
\newcolumntype{C}{>{\centering\arraybackslash}p{5em}}
\newcommand{\mr}{\mathrm}
\newcommand{\squeezeup}{\vspace{-2.5mm}}
\newcommand{\mb}{\mathbf}
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}
\newcommand{\bea}{\begin{algorithmic}}
\newcommand{\eea}{\end{algorithmic}}
\renewcommand{\vec}{\mbox{vec}}

\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\ceil}{s O{} m}{%
  \IfBooleanTF{#1} % starred
    {\left\lceil#3\right\rceil} % \ceil*[..]{..}
    {#2\lceil#3#2\rceil} % \ceil[..]{..}
}

\usepackage{cleveref}
\usepackage{bm}

\usepackage[title]{appendix}
\usepackage{url}
\usepackage{soul}

\usepackage{colortbl} % For coloring table cells

\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{soul}

\DeclareRobustCommand{\code}[1]{%
  \texorpdfstring{{\sethlcolor{gray}\hl{\texttt{#1}}}}%
                 {#1}%
}
\soulregister{\code}{1}

\crefname{section}{§}{§§}
\Crefname{section}{§}{§§}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

不确定是否有任何软件包会导致冲突或者我遇到的任何问题。

任何帮助都将不胜感激!

更新:
\colorbox 对我有用。

\subsection{\colorbox{yellow}{Computation Time}}

3

  • 我认为您不能在章节标题中使用它 – 至少在没有为目录/标题等指定替代方案的情况下。您的大部分序言都是无关紧要的,可以为这个问题而删除。请删除不必要的内容。您还应该完成您的代码,以便我们可以编译它来重现错误。题外话:如果您不清理它,您的序言会给您带来麻烦。不要多次加载包。不要加载有冲突的包。按正确的顺序加载包。例如hyperref应该晚点,但cleveref应该更晚。


    – 

  • 为什么我无法突出显示某个部分的标题?我该怎么做?


    – 

  • 请参阅下面 Werner 的回答;)。正如我所说,您必须提供一个非突出显示的替代方案以供在其他地方使用。例如,您不能在书签等处突出显示。


    – 


最佳答案
2

解决此问题的最佳方法是为文内设置\section和浮动参数部分提供单独的参数,即使它们可能是重复的。

\documentclass{spieman}
% https://spie.org/conferences-and-exhibitions/future-sensing-technologies/presenters/manuscript-submission-guidelines#_=_

\usepackage{soul}

\begin{document}

\section[A section]{A \hl{section}}

\end{document}

一般来说,部分标题可能被视为脆弱的,因为它们会浮动到文档的其他部分(如页眉、目录和 PDF 书签)。通过可选参数提供干净的文本内容通常有助于解决这些问题。

hyperref尝试创建书签时发生错误。

解决方法很简单。

\documentclass{spieman}

\usepackage{soul}

% make hyperref ignore \hl in bookmarks
\pdfstringdefDisableCommands{\let\hl=\relax}

\begin{document}

\section{A \hl{section}}

\end{document}