使用 natbib 的数字选项将参考文献中的条目放在一行时,条目之间会有额外的空格

使用 natbib 的数字选项将参考文献中的条目放在一行时,条目之间会有额外的空格

(注:我不确定这是否属于同一个问题将参考书目缩减为一行,并附上点和参考编号。我尝试进行编辑,但由于问题更改过多而被拒绝,因此我将其作为新问题提出。)

我正在尝试使用来自 Mico 的代码将我的参考资料放在一行上:

\usepackage[numbers]{natbib}
\renewenvironment{thebibliography}[1]{%
    \section*{\refname}
    \let\par\relax\let\newblock\relax
    \inparaenum[{[}1{]}]}{\endinparaenum}

但是,这会在某些条目之间产生多余的空格:

在此处输入图片描述

请注意条目 2 的结尾和条目 3 的开头之间的额外空格。

添加以下代码可以修复多余的空间,但会使所有文内引用都显示为问号:

\renewcommand{\bibitem}[2][]{\item}

此外,删除该numbers选项也会\usepackage{natbib}去掉多余的空间,但我想避免使用作者年份引用。

是否有人知道如何在使用数字选项时去除多余的空格,而不破坏文内引用?

梅威瑟:

\documentclass{article}

\usepackage[numbers]{natbib} % Removing numbers option fixes extra space
\usepackage{paralist}

\begin{filecontents}{bib.bib}
    @article{test1,
        Author = {Test Test},
        Year = {0000},
        Title = {Some title},
        Journal = {Some journal},
        Volume = {0},
        Pages = {0}
    }
    @article{test2,
        Author = {Test2 Test2},
        Year = {0001},
        Title = {Some other title},
        Journal = {Some other journal},
        Volume = {1},
        Pages = {1}
    }
    @article{test3,
        Author = {Test3 Test3},
        Year = {0002},
        Title = {Yet another title},
        Journal = {Yet another journal},
        Volume = {2},
        Pages = {2}
    }
\end{filecontents}

% Redefine the bibliography to go on one line
\renewenvironment{thebibliography}[1]{%
    \section*{\refname}%
    \let\par\relax\let\newblock\relax
    \inparaenum[{[}1{]}]}{\endinparaenum}

% Uncommenting the following makes the extra space go away but breaks in-text citations   
%\renewcommand{\bibitem}[2][]{\item}

\begin{document}
    \citet{test1,test2,test3}
    \bibliography{bib}{}
    \bibliographystyle{plainnat}
\end{document} 

答案1

正如您的评论所说,您想删除宏中的语句\hfil中的。具体来说,它显示为\item\@lbibitem

   \item[\hfil\NAT@anchor{#2}{\NAT@num}]%

在 中natbib.sty。您可以使用etoolbox进行替换,如下所示:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@lbibitem}{\item[\hfil}{\item[}{}{}
\makeatother

一旦natbib加载完成。请注意此代码周围的使用,因为宏名称中\makeatletter...\maketother存在,参见@\makeatletter 解释

示例输出

\begin{filecontents}{bib.bib}
    @article{test1,
        Author = {Test Test},
        Year = {0000},
        Title = {Some title},
        Journal = {Some journal},
        Volume = {0},
        Pages = {0}
    }
    @article{test2,
        Author = {Test2 Test2},
        Year = {0001},
        Title = {Some other title},
        Journal = {Some other journal},
        Volume = {1},
        Pages = {1}
    }
    @article{test3,
        Author = {Test3 Test3},
        Year = {0002},
        Title = {Yet another title},
        Journal = {Yet another journal},
        Volume = {2},
        Pages = {2}
    }
\end{filecontents}
\documentclass{article}

\usepackage[numbers]{natbib}
\usepackage{paralist}
\usepackage{etoolbox}


% Redefine the bibliography to go on one line
\renewenvironment{thebibliography}[1]{%
    \section*{\refname}%
    \let\par\relax\let\newblock\relax
    \inparaenum[{[}1{]}]}{\endinparaenum}

\makeatletter
\patchcmd{\@lbibitem}{\item[\hfil}{\item[}{}{}
\makeatother

\begin{document}

\citet{test1,test2,test3}

\bibliography{bib}
\bibliographystyle{plainnat}

\end{document}

相关内容