答案1
如果你的参考书目条目很短,那么放在标签编号下方的图标可能会与下一个条目的标签编号冲突。因此,我建议将图标放在标签的左侧,并附上来自奥黛丽的回答到使用 biblatex 和 moderncv 创建参考书目为了更好地moderncv
兼容书目环境,那里有足够的空间。
图标可以从中取出fontawesome5
并可以定位\raisebox
(这段代码的灵感来自沃纳的回答到如何在枚举项旁边添加符号?) 和少许\hspace
。
有很多方法可以告诉biblatex
哪些条目应该用图标显示。最大的问题是您是否想在文件中或在文件中告诉biblatex
图标。.bib
.tex
从文件设置图标.bib
:options
在这里我使用了条目中的条目选项.bib
,但相同的原则可以应用于类别(见下文)。
\documentclass[british]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric, backend=biber]{biblatex}
\usepackage{fontawesome5}
\newcommand*{\printmedalicon}{%
\raisebox{-1pt}[0pt][0pt]{\faIcon{medal}\hspace{1em}}}
\newtoggle{bbx:showicon}
\DeclareEntryOption[boolean]{showicon}{\settoggle{bbx:showicon}{#1}}
\newbibmacro*{showmedalicon}{%
\iftoggle{bbx:showicon}
{\printmedalicon}
{}}
\defbibenvironment{bibliography}
{\list
{\usebibmacro{showmedalicon}%
\printtext[labelnumberwidth]{% label format from numeric.bbx
\printfield{labelprefix}%
\printfield{labelnumber}}}
{\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
\setlength{\labelwidth}{\hintscolumnwidth}%
\setlength{\labelsep}{\separatorcolumnwidth}%
\leftmargin\labelwidth%
\advance\leftmargin\labelsep}%
\sloppy\clubpenalty4000\widowpenalty4000}
{\endlist}
{\item}
\moderncvstyle{classic}
\moderncvcolor{burgundy}
\firstname{Jane}
\familyname{Doe}
\begin{filecontents}{\jobname.bib}
@book{appleby,
author = {Humphrey Appleby},
title = {On the Importance of the Civil Service},
date = {1980},
options = {showicon},
}
@book{elk,
author = {Anne Elk},
title = {A Theory on Brontosauruses},
date = {1972},
options = {showicon},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{sigfridsson,aksin,appleby,elk}
\printbibliography
\end{document}
从文件中设置图标.tex
:类别
\documentclass[british]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric, backend=biber]{biblatex}
\usepackage{fontawesome5}
\newcommand*{\printmedalicon}{%
\raisebox{-1pt}[0pt][0pt]{\faIcon{medal}\hspace{1em}}}
\DeclareBibliographyCategory{showicon}
\newbibmacro*{showmedalicon}{%
\ifcategory{showicon}
{\printmedalicon}
{}}
\defbibenvironment{bibliography}
{\list
{\usebibmacro{showmedalicon}%
\printtext[labelnumberwidth]{% label format from numeric.bbx
\printfield{labelprefix}%
\printfield{labelnumber}}}
{\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
\setlength{\labelwidth}{\hintscolumnwidth}%
\setlength{\labelsep}{\separatorcolumnwidth}%
\leftmargin\labelwidth%
\advance\leftmargin\labelsep}%
\sloppy\clubpenalty4000\widowpenalty4000}
{\endlist}
{\item}
\moderncvstyle{classic}
\moderncvcolor{burgundy}
\firstname{Jane}
\familyname{Doe}
\addtocategory{showicon}{sigfridsson,nussbaum}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{sigfridsson,aksin,worman,nussbaum}
\printbibliography
\end{document}
答案2
另一种方法是调整begentry
bibmacro 以在左边距显示图标。我还没有用数字书目样式测试过这种方法,但它适用于作者-年份样式。
更准确地说,我用它来包含链接到 DOI 和 URL 的图标(灵感来自美国经济评论):
% !BIB program = biber
\documentclass{article}
\usepackage{fontawesome5}
\usepackage[colorlinks = true, urlcolor = blue]{hyperref}
\usepackage[backend = biber, bibstyle = authoryear]{biblatex}
\renewbibmacro*{begentry}{%
\hspace{-1.67em}% Protrude into left margin
\makebox[1.67em][l]{%
\iffieldundef{doi}{% Check if DOI provided
% DOI not provided:
\iffieldundef{url}{% Check if URL provided
% URL not provided: Print nothing
}{%
% URL provided:
\href{%
\thefield{url}% Link to URL
}{%
\raisebox{0.1ex}{\footnotesize\faIcon{external-link-alt}}% Print icon
}
}
}{%
% DOI provided:
\href{%
https://doi.org/\thefield{doi}% Link to DOI website
}{%
\raisebox{0.067ex}{\small\faIcon[regular]{file-alt}}% Print icon
}%
}%
}%
}
%\DeclareFieldFormat{doi}{} % Suppress output of DOI
%\DeclareFieldFormat{url}{} % Suppress output of URL
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{markey, nussbaum, sigfridsson, worman}
\printbibliography
\end{document}
这是输出:
如果您认为不需要打印 DOI 和 URL,您可以通过以下方式抑制这些字段的输出:
\DeclareFieldFormat{doi}{} % Suppress output of DOI
\DeclareFieldFormat{url}{} % Suppress output of URL
这使得参考书目不那么混乱: