TransWikia.com

How do I reduce whitespace or stretching in the bibliography?

TeX - LaTeX Asked by freeradical on August 16, 2021

How do I reduce whitespace in between words in the bibliography? It seems it’s trying to stretch things out to fit into the column. For example:

example

Here is the test document:

% test.tex
title{Article Title}
author{Some Author}
documentclass[12pt, a4paper, twocolumn]{article}
usepackage[super,comma,sort&compress]{natbib}
begin{filecontents}{test.bib}
@misc{LinkReference1,
  author = {Xxxxxxxxxx, Xxxxx},
  title = {Xxxxx-xxxxx Xxxxxxxxxxxxxx: Xxxxxx Xxxx},
}
end{filecontents}
begin{document}
maketitle
section{Section1Title}
Hello World.
nocite{*}
bibliographystyle{plain}
bibliography{test}
end{document}

% Create PDF on Linux:
% FILE=test; pkill -9 -f ${FILE} &>/dev/null; rm -f ${FILE}*aux ${FILE}*bbl ${FILE}*bib ${FILE}*blg ${FILE}*log ${FILE}*out ${FILE}*pdf &>/dev/null; pdflatex -halt-on-error ${FILE}; bibtex ${FILE} && pdflatex ${FILE} && pdflatex ${FILE} && (xdg-open ${FILE}.pdf &)

2 Answers

Many .bst styles use the command newblock to separate (larger) chunks of information. In the example the .bbl file will contain a newblock after the author name directly at the position marked in red.

bibitem{LinkReference1}
Xxxxx Xxxxxxxxxx.
newblock Xxxxx-xxxxx xxxxxxxxxxxxxx: Xxxxxx xxxx.

Note that there is a normal space (or in this case line break) before newblock as well.

The standard classes define

newcommandnewblock{hskip [email protected]@minus.07em}

which means that an additional (quite) stretchable space is inserted by newblock.

natbib, which you use, also has

renewcommandnewblock{hskip .11em @plus.33em @minus.07em}

but does that definition inside thebibliography, which means that if you want to modify newblock you will have to either redefine thebibliography or work from within the environment (for example by manually modifying the .bbl file or by using @preamble together with a .bst file that executes the @preamble commands within the environment [there are some that do this, but the majority of styles executes @preamble before begin{thebibliography}]).

In your example then

makeatletter
renewenvironment{thebibliography}[1]{%
 bibsection
 parindentz@
 bibpreamble
 bibfont
 list{@biblabel{thec@NAT@ctr}}{@bibsetup{#1}globalc@NAT@ctrz@}%
 ifNAT@openbib
   renewcommandnewblock{par}%
 else
   renewcommandnewblock{}%
 fi
 sloppyclubpenalty4000widowpenalty4000
 sfcode`.@m
 letNAT@bibitem@first@sw@firstoftwo
    letciteNcite letshortcitecite
    letciteasnouncite
}{%
 bibitem@fin
 bibpostamble
 def@noitemerr{%
  PackageWarning{natbib}{Empty `thebibliography' environment}%
 }%
 endlist
 bibcleanup
}%
makeatother

would remove the additional space inserted by newblock. But the spacing does not get better

Example bibliography: There are huge spaces between all words in the first line.

Arguably it gets worse, because the given and family name, which form one unit, are separated by the same space that separates the name and the title.


Line breaking in the bibliography is hard at the best of times (names and technical jargon might be hard to hyphenate properly, URLs make things complicated, ...), but two-column mode it gets even harder because the available space is much smaller than usual. It is therefore expected that space needs to be stretched and compressed a bit for full justification.

In this case it is well worth considering setting the bibliography ragged right, i.e. turning off the justification. See for example How to prevent automatic justification of references?. LaTeX will stop stretching space, but the text will not line up at the end of the line. Since the bibliography is list-like and probably has a high number of lines that don't meet the right margin anyway, the visual effect will not be as big as in a normal paragraph of flowing text.

documentclass[12pt, a4paper, twocolumn]{article}
usepackage[super,comma,sort&compress]{natbib}
%usepackage{filecontents}
begin{filecontents}{test.bib}
@misc{LinkReference1,
  author = {Xxxxxxxxxx, Xxxxx},
  title = {Xxxxx-xxxxx Xxxxxxxxxxxxxx: Xxxxxx Xxxx},
}
end{filecontents}

renewcommand*{bibfont}{raggedright}

begin{document}
Hello World.
nocite{*}

bibliographystyle{plain}
bibliography{test}
end{document}

the overall result is much more pleasant

No excessive white space in the first line. The <code>newblock</code> still adds a wee bit of additional space after the period.

If you like hyphenation in ragged right text, you may want to look into ragged2e's RaggedRight.

Correct answer by moewe on August 16, 2021

As pointed out by moewe, when using natbib, one has to redefine newblock inside the thebibliography environment. A relatively simple solution that does exactly this is:

let thebibliographyorig thebibliography
renewcommand{thebibliography}[1]{%
    thebibliographyorig{#1}%
    renewcommand{newblock}{}%
}

Answered by Holger Gerhardt on August 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP