平均能量损失

平均能量损失

以下源文件test.tex是可以的:

% file test.tex
\documentclass[draft]{memoir}

\usepackage[usenames]{xcolor}

\makeindex
% OK:
\indexmarkstyle{\normalfont\small\sffamily}
% Not OK: it colors text itself:
%\indexmarkstyle{\normalfont\small\sffamily\color{red}}
\showindexmarks

\begin{document}

\tableofcontents

\chapter{We begin}

Hello\index{Hello} to the World\index{World}!

\bigskip
abc \index{alphabet!abc} is before def.

\printindex

\end{document} 

我们将使用索引样式文件:

% file test.ist
headings_flag 1
heading_prefix "{\\medskip\\hfill\\large\\textsf{\\textbf{"
heading_suffix "}}\\hfill}\\medskip\\nopagebreak\n"

\showindexmarks但是,如果我尝试通过注释掉第一\indexmarkstyle行并取消注释第二行(包括以下内容)来为边距中显示的索引项着色,\color{red}则:

  • 那些显示的边际索引项根据需要被标为红色;
  • 靠近正文的部分内容也是如此\index以及整个章节标题也是如此,不是当然想要。

查看该章节的输出:

颜色从 \indexmarkstyle 泄漏到文本中。

如何避免颜色泄漏到正文中?

答案1

您可以通过确保索引标记样式和索引标记位于一个组内来解决此问题,但默认情况下不会这样做。

memoir似乎经常放在\normalfont\normalsize任何地方,因此字体不会对索引标记以外的内容产生太大影响。但对 的调用并不多\normalcolor

将此添加到您的序言中:

\makeatletter
\renewcommand{\@showidx}[1]{%
  \insert\@indexbox{%
    \begingroup% add begin group
    \@sanitizeat
    \the\indexmarkstyle
    \hsize\marginparwidth
    \hangindent\marginparsep \parindent\z@
    \everypar{}\let\par\@@par \parfillskip\@flushglue
    \lineskip\normallineskip
    \baselineskip .8\normalbaselineskip\sloppy
    \raggedright \leavevmode
    \vrule \@height .7\normalbaselineskip \@width \z@\relax
      #1\relax
    \vrule \@height \z@ \@depth .3\normalbaselineskip \@width \z@\relax
    \endgroup% add end group
  }%
  \ifhmode\penalty\@M \hskip\z@skip\fi}
\makeatother

平均能量损失

\documentclass[draft]{memoir}

\usepackage[usenames]{xcolor}

\makeindex
% OK:
\indexmarkstyle{\normalfont\small\sffamily}
% Not OK: it colors text itself:
\indexmarkstyle{\normalfont\small\sffamily\color{red}}
\showindexmarks

\makeatletter
\renewcommand{\@showidx}[1]{%
  \insert\@indexbox{%
    \begingroup% add begin group
    \@sanitizeat
    \the\indexmarkstyle
    \hsize\marginparwidth
    \hangindent\marginparsep \parindent\z@
    \everypar{}\let\par\@@par \parfillskip\@flushglue
    \lineskip\normallineskip
    \baselineskip .8\normalbaselineskip\sloppy
    \raggedright \leavevmode
    \vrule \@height .7\normalbaselineskip \@width \z@\relax
      #1\relax
    \vrule \@height \z@ \@depth .3\normalbaselineskip \@width \z@\relax
    \endgroup% add end group
  }%
  \ifhmode\penalty\@M \hskip\z@skip\fi}
\makeatother

\begin{document}

\tableofcontents

\chapter{We begin}

Hello\index{Hello} to the World\index{World}!

\bigskip
abc \index{alphabet!abc} is before def.

\printindex

\end{document} 

MWE 输出

相关内容