我有一个 Biber 书目,其中某些作品用特殊关键字标记。当 Biblatex 打印参考文献列表(作者-年份格式)时,我希望它用一些标记(例如星号)注释这些条目。因此我尝试了以下方法:
\documentclass{article}
\usepackage{calc}
\usepackage[bibstyle=authoryear]{biblatex}
\addbibresource{\jobname.bib}
\renewbibmacro*{begentry}{\ifkeyword{ownwork}{\textasteriskcentered\addspace}{}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{foo,
author = {Foo},
title = {Foo},
booktitle = {Foo},
year = {2017},
}
@inproceedings{bar,
author = {Bar},
title = {Bar},
booktitle = {Bar},
year = {2017},
keywords = {ownwork},
}
\end{filecontents}
\begin{document}
\nocite{foo,bar}
\printbibliography
\end{document}
但是,我希望这些星号出现在左边距,以便参考文献的作者列表对齐。我尝试将的定义更改为begentry
以下内容,使用\widthof
而不是绝对宽度(以避免我必须猜测要使用多少空间,并使命令能够抵御字体大小的变化)。但是,它不起作用:
\renewbibmacro*{begentry}{%
\ifkeyword{ownwork}{%
\setlength{\dimen0}{-\widthof{\textasteriskcentered\addspace}}%
\hspace{\dimen0}\textasteriskcentered\addspace%
}{}}
我做错了什么?我怎样才能将标记稍微放在参考书目条目的左侧?
答案1
您只需将文本放在宽度为零的框中:
\documentclass{article}
\usepackage{calc}
\usepackage[bibstyle=authoryear]{biblatex}
\addbibresource{\jobname.bib}
\renewbibmacro*{begentry}{\ifkeyword{ownwork}{\makebox[0pt][r]{\textasteriskcentered\addspace}}{}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{foo,
author = {Foo},
title = {Foo},
booktitle = {Foo},
year = {2017},
}
@inproceedings{bar,
author = {Bar},
title = {Bar},
booktitle = {Bar},
year = {2017},
keywords = {ownwork},
}
\end{filecontents}
\begin{document}
\nocite{foo,bar}
\printbibliography
\end{document}
答案2
我们可以使用 egreg 的解决方案来在文本左侧添加标记
\documentclass{article}
\usepackage[bibstyle=authoryear]{biblatex}
\addbibresource{\jobname.bib}
\newcommand{\impmark}{\strut\vadjust{\domark}}
\newcommand{\domark}{%
\vbox to 0pt{
\kern-\dp\strutbox
\smash{\llap{*\kern1em}}
\vss
}%
}
\renewbibmacro*{begentry}{\ifkeyword{ownwork}{\impmark}{}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{foo,
author = {Foo},
title = {Foo},
booktitle = {Foo},
year = {2017},
}
@inproceedings{bar,
author = {Bar},
title = {Bar},
booktitle = {Bar},
year = {2017},
keywords = {ownwork},
}
\end{filecontents}
\begin{document}
\nocite{foo,bar}
\printbibliography
\end{document}