0

I'm making an annotated bibliography like the following MWE, thanks to moewe's answer. I would like to prevent a page break in a bib item, though the page break between the items is tolerable. A similar question has already been resolved, but the question and answers seems to be related to natbib and I need solutions for biblatex.

I tried to use wrap an item with vbox, but in vain. Do you have any idea?

enter image description here

MWE

\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 Answers1

2

If you don't want your \par to allow a page break, issue a \nopagebreak after it (What is the difference between \nobreak and \nolinebreak?).

If you don't want line breaks to occur between 'normal' lines in your bibliography, increase \interlinepenalty to 10,000 (How to avoid page-breaks inside paragraphs?). The value is set in \bibsetup, so we append the new value to that macro.

\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}

moewe
  • 175,683