我正在制作一个带注释的参考书目,如以下 MWE,感谢moewe 的回答。我想防止 bib 项目中出现分页符,尽管项目之间的分页符是可以容忍的。类似的问题已经解决,但问题和答案似乎与有关natbib
,我需要解决方案biblatex
。
我尝试使用 包裹物品vbox
,但没有成功。您有什么想法吗?
平均能量损失
\documentclass{article}
\usepackage[backend = biber, style = apa, citestyle = numeric]{biblatex}
\renewbibmacro*{annotation}{%
\ifboolexpr{ test {\iffieldundef{annotation}}
or not togl {bbx:annotation}}
{}
{\begingroup
\togglefalse{blx@bibliography}%
\newline
\setunit{}%
\printfield{annotation}%
\endgroup}
\iffieldundef{abstract}
{}
{\begingroup
\togglefalse{blx@bibliography}%
\setunit{%
\par
\vspace{0.5\baselineskip}}%
\bibstring[\mkbibbold]{abstract}%
\setunit{\newline}%
\printfield{abstract}%
\endgroup}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\defbibenvironment{bibliography}
{\list
%\vbox{
{\printtext[labelnumberwidth]{%
\printfield{labelprefix}%
\printfield{labelnumber}}}
{%\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}% %\bibitemsep
\setlength{\parsep}{\bibparsep}%
\setlength{\itemindent}{0\labelsep}%
\setlength{\listparindent}{0\labelsep}%
}%
\renewcommand*{\makelabel}[1]{\hss##1}}
%}
{\endlist}
{\item}
\begin{filecontents*}{\jobname.bib}
@Manual{R-rmarkdown,
title = {rmarkdown: Dynamic Documents for {R}},
author = {JJ Allaire and Yihui Xie and Jonathan McPherson
and Javier Luraschi and Kevin Ushey and Aron Atkins
and Hadley Wickham and Joe Cheng and Winston Chang
and Richard Iannone},
year = {2020},
note = {R package version 2.3},
url = {https://github.com/rstudio/rmarkdown},
abstract = {This is a good book. That's why I cite this.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.}
}
@Book{knitr2015,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {https://yihui.org/knitr/},
abstract = {This is a good book. That's why I cite this.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.}
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{R-rmarkdown, knitr2015}
\printbibliography[title=References]
\end{document}
答案1
如果您不想\par
允许分页符,请在分页\nopagebreak
符后发出 (\nobreak 和 \nolinebreak 之间有什么区别?)。
如果你不希望参考书目中的“正常”行之间出现换行符,请增加到\interlinepenalty
10,000(如何避免段落内分页?)。该值已在中设置\bibsetup
,因此我们将新值附加到该宏。
\documentclass{article}
\usepackage[backend = biber, style = apa, citestyle = numeric]{biblatex}
\appto{\bibsetup}{%
\interlinepenalty=100000\relax}
\renewbibmacro*{annotation}{%
\ifboolexpr{ test {\iffieldundef{annotation}}
or not togl {bbx:annotation}}
{}
{\begingroup
\togglefalse{blx@bibliography}%
\newline
\setunit{}%
\printfield{annotation}%
\endgroup}%
\iffieldundef{abstract}
{}
{\begingroup
\togglefalse{blx@bibliography}%
\setunit{%
\par\nopagebreak
\vspace{0.5\baselineskip}}%
\bibstring[\mkbibbold]{abstract}%
\setunit{\newline}%
\printfield{abstract}%
\endgroup}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\defbibenvironment{bibliography}
{\list
{\printtext[labelnumberwidth]{%
\printfield{labelprefix}%
\printfield{labelnumber}}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}
\begin{filecontents*}{\jobname.bib}
@manual{R-rmarkdown,
title = {rmarkdown: Dynamic Documents for {R}},
author = {J. J. Allaire and Yihui Xie and Jonathan McPherson
and Javier Luraschi and Kevin Ushey and Aron Atkins
and Hadley Wickham and Joe Cheng and Winston Chang
and Richard Iannone},
year = {2020},
note = {R package version 2.3},
url = {https://github.com/rstudio/rmarkdown},
abstract = {This is a good book. That's why I cite this.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.},
}
@book{knitr2015,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {https://yihui.org/knitr/},
abstract = {This is a good book. That's why I cite this.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\nocite{R-rmarkdown, knitr2015}
\printbibliography[title=References]
\end{document}