Non-breaking space in \citet using natbib?
Looks like \NAT@spacechar
needs to be redefined:
\documentclass{article}
\usepackage[numbers]{natbib}
\makeatletter
% \def\NAT@spacechar{\ }% OLD
\def\NAT@spacechar{~}% NEW
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{a01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
\end{filecontents}
\begin{document}
Let's test if author and citation number end up in different lines: \citet{a01}.
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
Since \NAT@spacechar
is used, this redefinition prevents such breaks:
\makeatletter
\renewcommand*{\NAT@spacechar}{~}
\makeatother
This could affect also places where a break could be desired. Thus, an easy way for your rare occasions would be to use just \mbox
around the citation:
... in the paper \mbox{\citet{interesting}}.
lockstep and Stefan Kottwitz suggest redefining \NAT@spacechar
. That may have worked at one time, but I find that it no longer works now, seven years later, using natbib 2010/09/13 8.31b (PWD, AO)
from TeXLive 2016. A comment from @penelope also mentions that this approach was no longer working as of mid-2014.
The following strategy does work for me as of now. Add the following to your document preamble somewhere after \usepackage{natbib}
:
\bibpunct{\nolinebreak{}[}{]}{,}{n}{}{,}
The key piece of this is the \nolinebreak{}[
, which discourages LaTeX from breaking a line before the [
that starts a group of bracketed citation numbers. The remaining arguments to \bibpunct
merely replicate the standard punctuation for bracketed, numbered citations.
Note that the {}
immediately after \nolinebreak
is not really an empty argument to \nolinebreak
. Rather, it simply prevents \nolinebreak
from mistaking the following [
for the start of an optional argument. That being said, \nolinebreak
does accept an optional argument that determines how strongly a break should be discouraged. So you could instead use something like \bibpunct{\nolinebreak[0][}{]}{,}{n}{}{,}
to make the no-break directive merely a mild request, all the way up to \bibpunct{\nolinebreak[4][}{]}{,}{n}{}{,}
for a strict demand. The latter is equivalent to the default treatment you get if you use the \bibpunct{\nolinebreak{}[}{]}{,}{n}{}{,}
form I suggested initially.