2

I am struggling with excessive white space in my bibliography entry. This question has been asked before, but the commonly prescribed advice of including the hyphens option of the url package before hyperref is not working for me.

Here is a reproducible example:

\documentclass{article}
\usepackage{natbib}
\usepackage[margin=1in]{geometry}
\usepackage[hyphens,spaces,obeyspaces]{url}
\usepackage[hidelinks,breaklinks]{hyperref}
\begin{document}
    \bibliographystyle{apalike} 
    \bibliography{mini}
    \nocite{*}
\end{document}

and my file mini.bib

@misc{feilden2017,
  title = {Most Scientists 'Can't Replicate Studies'},
  abstract = {Science is facing a "reproducibility crisis" as scientists fail to reproduce others' work, it is claimed.},
  language = {en-GB},
  howpublished = {\url{https://web.archive.org/web/20190413132210/https://www.bbc.com/news/science-environment-39054778}},
  author = {Feilden, Tom},
  month = feb,
  year = {2017}
}

The result looks like: enter image description here

  • you could set your bibliography \raggedright or set up url to allow breaking anywhere not just at / etc – David Carlisle Jun 05 '19 at 20:22
  • 3
    Try loading the xurl package, to have more breaking points for urls – Bernard Jun 05 '19 at 20:27
  • 1
    I am using a Wiley template and \usepackage[sectionbib,numbers,sort]{natbib}% for numbered citation comment the above line \usepackage{hyperref} """ """ etc \incliude(ch01) "" ""etc \nocite{*} \bibliography{wiley} \latexprintindex \end{document} and in wiley.bib @misc{SF1, author = {foo}, title = {bar}, year = {2023}, url = {https://foo{_}overflow.txt}, note = {Accessed: 26/8/23} } I had to press the biBTex button several times and to quick build several times to get a stable bibliography. Thank you for posting!! – Michael Aug 26 '23 at 17:01

1 Answers1

4

As @Bernard has already suggested in a comment, you should replace

\usepackage[hyphens,spaces,obeyspaces]{url}

with

\usepackage[obeyspaces]{xurl}

Loading the xurl package instead of the url package allows URL strings to be line-broken not just a hyphen and space (and slash) characters, but at any character. I would still specify the option obeyspaces, though, as otherwise space characters in URL strings will be suppressed entirely.

As an entirely welcome byproduct of using xurl, the unsightly whitespace gaps in other parts of the typeset bib entries will vanish automatically.

Oh, the xurl package is of fairly recent vintage; this probably explains why you couldn't find it mentioned in the early posting you've referenced in your query.

enter image description here

\RequirePackage{filecontents}
\begin{filecontents}{mini.bib}
@misc{feilden2017,
  title = {Most Scientists `Can't Replicate Studies'},
  abstract = {Science is facing a ``reproducibility 
      crisis'' as scientists fail to reproduce others' 
      work, it is claimed.},
  language = {en-GB},
  howpublished = {\url{https://web.archive.org/web/20190413132210/https://www.bbc.com/news/science-environment-39054778}},
  author = {Feilden, Tom},
  month = feb,
  year = {2017}
}
\end{filecontents}

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apalike} 
\usepackage[margin=1in]{geometry}
\usepackage[obeyspaces]{xurl}
\usepackage[hidelinks]{hyperref}

\begin{document}
\nocite{*}
\bibliography{mini}    
\end{document}
Mico
  • 506,678