我发现这个很好的答案。但是,我在引用数 >=10 时遇到了对齐问题。
例如:
请注意,>= 10 的项目比 <9 的项目缩进更多。我希望所有项目都遵循(默认)相同的对齐方式。
下列的答案我用了:
\documentclass{article}
\usepackage[backend=bibtex,style=numeric,sorting=ydnt]{biblatex}
\begin{filecontents}{library.bib}
@article{foo1,
author = {Author 1, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo2,
author = {Author 2, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo3,
author = {Author 3, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo4,
author = {Author 4, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo5,
author = {Author 5, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo6,
author = {Author 6, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo7,
author = {Author 7, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo8,
author = {Author 8, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo9,
author = {Author 9, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo10,
author = {Author 10, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo11,
author = {Author 11, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
\end{filecontents}
% Count total number of entries in each refsection
\AtDataInput{%
\csnumgdef{entrycount:\therefsection}{%
\csuse{entrycount:\therefsection}+1}}
% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
\number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}
\addbibresource[label=myname]{library.bib}
\begin{document}
\begin{refsection}[myname]
\nocite{*}
\printbibliography[title={My title}]
\end{refsection}
\end{document}
答案1
这里的问题是biblatex
需要测量数字标签的宽度以进行正确对齐。这通常发生在从文件中读取条目时.bbl
。由于编号会根据文件中的条目数而变化.bbl
,因此在数据输入时获得的宽度测量是不正确的。
现代最快的解决方案biblatex
可能是将选项传递locallabelwidth
给printbibliography
。这样,当所有编号都固定时,所需的宽度测量将在本地执行(仅适用于此特定书目)。
\documentclass{article}
\usepackage[backend=bibtex,style=numeric,sorting=ydnt]{biblatex}
% Count total number of entries in each refsection
\AtDataInput{%
\csnumgdef{entrycount:\therefsection}{%
\csuse{entrycount:\therefsection}+1}}
% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
\number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}
\begin{filecontents}{library.bib}
@article{foo1,
author = {Author 1, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo2,
author = {Author 2, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo3,
author = {Author 3, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo4,
author = {Author 4, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo5,
author = {Author 5, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo6,
author = {Author 6, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo7,
author = {Author 7, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo8,
author = {Author 8, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo9,
author = {Author 9, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo10,
author = {Author 10, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
@article{foo11,
author = {Author 11, A.},
title = {Title},
journal = {Journal},
year = {2013},
volume = {13},
pages = {123-234}
}
\end{filecontents}
\addbibresource[label=myname]{library.bib}
\begin{document}
\begin{refsection}[myname]
\nocite{*}
\printbibliography[title={My title},locallabelwidth]
\end{refsection}
\end{document}