在交叉线文本上添加突出显示时,旁注的颜色会发生变化(使用灵魂包)

在交叉线文本上添加突出显示时,旁注的颜色会发生变化(使用灵魂包)

如下图所示,当我高亮显示交叉线文本时,同一行的边注中的文本颜色也会改变。

问题描述

代码如下:

\documentclass[onecolumn]{revtex4-1}
\usepackage{soul}
\usepackage{color, xcolor}
\usepackage{geometry}
 \geometry{ a4paper,   total={10cm,257mm},  left=10mm,  top=20mm, }
\begin{document}
\setlength\marginparwidth{8cm} 
\setlength\marginparsep{0.6cm} 
aaa 
\sethlcolor{yellow}\hl{bbb}\marginpar{\scriptsize{\textbf{bbb:}}} 
ccc dddd eeee ffff ggggg hhhhhh iiiiiii jjjjjjjj \
\sethlcolor{yellow}\hl{kkkkkkkkk kkkkkkkkkkk}
\marginpar{\scriptsize{\textbf{kkkkkkkkk kkkkkkkkkkk:} }}

aaa 
\sethlcolor{yellow}\hl{bbb}\marginpar{\scriptsize{\textbf{bbb:} }}
ccc dddd eeee ffff ggggg hhhhhh iiiiiii jjjjjjjj 
\sethlcolor{pink}
\hl{kkkkkkkkk kkkkkkkkkkk}
\marginpar{\scriptsize{\textbf{kkkkkkkkk kkkkkkkkkkk:} }}
\end{document}

有办法解决这个问题吗?

答案1

在此处输入图片描述

平均能量损失

\documentclass[onecolumn]{revtex4-1}
\usepackage{soul}
\usepackage{color, xcolor}
\usepackage{geometry}
  \geometry{ a4paper,   total={10cm,257mm},  left=10mm,  top=20mm, }

\makeatletter
\usepackage{etoolbox}
  \patchcmd{\@savemarbox}{\color@vbox}{\color@vbox\normalcolor}{}{}
\makeatother
    
\begin{document}
 \setlength\marginparwidth{8cm} 
 \setlength\marginparsep{0.6cm} 

 aaa 
 \sethlcolor{yellow}\hl{bbb}\marginpar{\scriptsize{\textbf{bbb:}}} 
 ccc dddd eeee ffff ggggg hhhhhh iiiiiii jjjjjjjj \
 \sethlcolor{yellow}\hl{kkkkkkkkk kkkkkkkkkkk}
 \marginpar{\scriptsize{\textbf{kkkkkkkkk kkkkkkkkkkk:} }}
 
 aaa 
 \sethlcolor{yellow}\hl{bbb}\marginpar{\scriptsize{\textbf{bbb:} }}
 ccc dddd eeee ffff ggggg hhhhhh iiiiiii jjjjjjjj 
 \sethlcolor{pink}
 \hl{kkkkkkkkk kkkkkkkkkkk}
 \marginpar{\scriptsize{\textbf{kkkkkkkkk kkkkkkkkkkk:} }}
\end{document}

编辑\patchcmd命令只是在\@savemarbox命令内部查找,搜索\color@vbox并用 替换它\color@vbox\normalcolor。当然,您可以\patchcmd通过\@savemarbox直接重新定义来避免使用:

\makeatletter
\long\def \@savemarbox #1#2{%
  \global\setbox #1%
    \color@vbox\normalcolor% <--- added \normalcolor here ---
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@marginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\makeatother

相关内容