当我使用 biblatex 阅读风格时,如何更改参考书目标题的颜色?

当我使用 biblatex 阅读风格时,如何更改参考书目标题的颜色?

根据答案https://tex.stackexchange.com/a/149753/4172针对这个问题突出显示特定的参考书目条目,我正在尝试使用 biblatex 的阅读风格获取参考列表,其中一些项目已突出显示。

我得到的代码如下(与上面提到的答案相同,不同之处在于我使用的是 biblatex 的阅读风格):

\documentclass[12pt]{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{cite1,
  author = {Knuth, Donald},
  title = {{Title One}},
  journal = {Some Journal},
  year = {2005},
  volume = {1},
  pages = {1--42},
}

@book{cite2,
  author = {Knuth, Donald},
  title = {{A Way More Important Title}},
  publisher = {Oxford},
  year = {2009},
  address = {New York}
}
\end{filecontents}

\usepackage[T1]{fontenc}
\usepackage[style=reading]{biblatex}
\addbibresource{\jobname.bib}

%% Highlight entries
\usepackage[svgnames]{xcolor}
\DeclareBibliographyCategory{important}
% the colour definition
\colorlet{impentry}{Maroon}% let 'impentry' = Maroon

% Inform biblatex that all books in the 'important' category deserve
% special treatment, while all others do not
\AtEveryBibitem{%
  \ifcategory{important}%
    {\bfseries\color{impentry}}%
    {}%
  }

% Add books to 'important' category in preamble
\addtocategory{important}{%
 cite2,
}


\begin{document}

\nocite{*}
\printbibliography

\end{document}

我得到的结果如下所示:

在此处输入图片描述

我如何才能更改第一个条目的标题颜色?也就是说,如何突出显示文本Knuth: A Way More Important Title cite2及其下方的相应下划线?

答案1

“标题”是使用 bibmacro entryhead:full(或entryhead:name,取决于传递给entryhead)创建的。

为了给入口头部着色,我们只需将代码应用\AtEveryBibitementryhead:full

\renewbibmacro*{entryhead:full}{%
  \ifcategory{important}
    {\bfseries\color{impentry}}
    {}
  \printnames[labelname][-1]{labelname}%
  \setunit*{\addcolon\space}%
  \printfield{labeltitle}}

这类似于entryhead:name

\makeatletter
\newbibmacro*{entryhead:name}{%
  \ifcategory{important}
    {\bfseries\color{impentry}}
    {}
  \ifnameundef{labelname}
    {\printfield{labeltitle}}
    {\printnames[labelname]{labelname}}%
  \savefield{fullhash}{\bbx@lasthash}}
\makeatother

如果您想让颜色更具局部性(不要为输入键着色),我们可以通过一些集体行动来实现:

\renewbibmacro*{entryhead:full}{%
  \begingroup
  \ifcategory{important}
    {\bfseries\color{impentry}}
    {}
  \printnames[labelname][-1]{labelname}%
  \setunit*{\addcolon\space}%
  \printfield{labeltitle}
  \endgroup}

平均能量损失

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[style=reading]{biblatex}
\addbibresource{biblatex-examples.bib}

%% Highlight entries
\usepackage[svgnames]{xcolor}
\DeclareBibliographyCategory{important}
% the colour definition
\colorlet{impentry}{Maroon}% let 'impentry' = Maroon

% Inform biblatex that all books in the 'important' category deserve
% special treatment, while all others do not
\AtEveryBibitem{%
  \ifcategory{important}%
    {\bfseries\color{impentry}}%
    {}%
  }

% Add books to 'important' category in preamble
\addtocategory{important}{%
 cicero,
}

\renewbibmacro*{entryhead:full}{%
  \ifcategory{important}
    {\bfseries\color{impentry}}
    {}
  \printnames[labelname][-1]{labelname}%
  \setunit*{\addcolon\space}%
  \printfield{labeltitle}}

\begin{document}
\nocite{wilde,cicero}
\printbibliography
\end{document}

在此处输入图片描述


如果您还想为水平规则着色,最好修改另一个宏(也就是说,您不必将自定义应用到entryhead:full上述内容)

\makeatletter
\def\bbx@item@full{%
  \begingroup
  \ifcategory{important}
    {\color{impentry}}
    {}
  \itemsep2\bibitemsep
  \@itempenalty\z@
  \item\relax
  \begingroup
  \samepage\bfseries
  \def\finentrypunct{\strut}%
  \usebibmacro{entryhead:full}%
  \ifbool{bbx:entrykey}
    {\def\newblockpunct{%
       \nobreak\hskip\z@skip\strut
       \hfill\penalty100\hskip1em\relax
       \hbox{}\nobreak\hfill\strut}%
     \def\finentrypunct{%
       \parfillskip\z@\finalhyphendemerits\z@
       \par\nobreak}%
     \newblock
     \printfield{entrykey}}
    {}%
  \finentry
  \endgroup
  \hrule height 1.25pt\relax
  \itemsep\bibitemsep
  \@itempenalty\@M
  \item\strut
  \@itempenalty\z@
  \endgroup}
\makeatother

平均能量损失

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[style=reading]{biblatex}
\addbibresource{biblatex-examples.bib}

%% Highlight entries
\usepackage[svgnames]{xcolor}
\DeclareBibliographyCategory{important}
% the colour definition
\colorlet{impentry}{Maroon}% let 'impentry' = Maroon

% Inform biblatex that all books in the 'important' category deserve
% special treatment, while all others do not
%\AtEveryBibitem{%
%  \ifcategory{important}%
%    {\bfseries\color{impentry}}%
%    {}%
%  }

% Add books to 'important' category in preamble
\addtocategory{important}{%
 cicero,
}

\AtEveryBibitem{%
  \ifcategory{important}%
    {\bfseries\color{impentry}}%
    {}%
}

\makeatletter
\def\bbx@item@full{%
  \begingroup
  \ifcategory{important}
    {\color{impentry}}
    {}
  \itemsep2\bibitemsep
  \@itempenalty\z@
  \item\relax
  \begingroup
  \samepage\bfseries
  \def\finentrypunct{\strut}%
  \usebibmacro{entryhead:full}%
  \ifbool{bbx:entrykey}
    {\def\newblockpunct{%
       \nobreak\hskip\z@skip\strut
       \hfill\penalty100\hskip1em\relax
       \hbox{}\nobreak\hfill\strut}%
     \def\finentrypunct{%
       \parfillskip\z@\finalhyphendemerits\z@
       \par\nobreak}%
     \newblock
     \printfield{entrykey}}
    {}%
  \finentry
  \endgroup
  \hrule height 1.25pt\relax
  \itemsep\bibitemsep
  \@itempenalty\@M
  \item\strut
  \@itempenalty\z@
  \endgroup}
\makeatother
\begin{document}
\nocite{wilde,cicero}
\printbibliography
\end{document}

相关内容