如何在表中引用引用键包含“&”的参考文献

如何在表中引用引用键包含“&”的参考文献

当我尝试使用 TexShop(带有 Tex Live 2016 发行版)直接在表格中引用参考文献时,遇到了问题。引用键包含“&”,我猜 LaTeX 可能会将其视为普通的表格分隔标记,尽管它位于“\citep{}”命令中。代码如下:

\documentclass[preprint]{aastex6}

\begin{document}

\begin{table}
\centering
\caption{Test for cite key contains `\&'. \label{tab:test}}
\begin{tabular}{lll}
Citation Failed     & {\citet{2007A&A...465..587S}} & Nothing appears\\
Citation Succeeded  & {\citet{2015MNRAS.453.1619A}} & A paper appears\\
\end{tabular}
\end{table}

I want to cite \citet{2007A&A...465..587S} in the table, 
whose cite key contains `\&', you can see the citation works 
here but not in the table. I didn't encounter this problem 
with CTeX in Windows, compiling the same script.

\bibstyle{aasjournal}
\bibliography{bbb.bib}

\end{document}

使用 LaTeX 排版会出现以下错误:

./aaa.tex:9: 缺少插入的 \endcsname。
将重新读取
\global
l.9 ...n 失败 & {\citet{2007A&A...465..587S}
} & 没有出现任何内容\

同时,.aux 将会得到错误的名称‘2007A&A...465..587S’:

\citation{2007A\global \advance \columncount by 1\relax \saveampersand A...465..587S}

应该是(如果您在文章的其他地方引用该论文,只要它不在表格中):

\citation{2007A&A...465..587S}

使用这个不正确的 .aux 文件,BibTeX 会告诉您:

参数中的空格---文件 aaa.aux 的第 19 行
:\citation{2007A\global
:\advance \columncount by 1\relax \saveampersand A...465..587S}
我将跳过此命令的其余部分

最后,引用不会出现在 .pdf 文件中,作为对比,表中引用的第二篇论文将会出现,如下所示:

pdf

是的,我可以通过删除“&”来更改引用键,然后问题就解决了,但是我试图弄清楚如何在不改变引用密钥的情况下解决问题,因为引用密钥通常由其他工具自动生成,而改变所有此类引用密钥并不是一件容易的事。

本例中使用的‘bbb.bib’是:

@article{2007A&A...465..587S,
Adsnote = {Provided by the SAO/NASA Astrophysics Data System},
Adsurl = {http://adsabs.harvard.edu/abs/2007A%26A...465..587S},
Author = {{Shi}, J.~R. and {Gehren}, T. and {Zhang}, H.~W. and {Zeng}, J.~L. and {Zhao}, G.},
Doi = {10.1051/0004-6361:20066709},
Journal = {\aap},
Keywords = {line: formation, line: profile, stars: abundance, stars: late-type, galaxies: evolution},
Month = apr,
Pages = {587-591},
Title = {{Lithium abundances in metal-poor stars}},
Volume = 465,
Year = 2007,
Bdsk-Url-1 = {http://dx.doi.org/10.1051/0004-6361:20066709}}

@article{2015MNRAS.453.1619A,
Adsnote = {Provided by the SAO/NASA Astrophysics Data System},
Adsurl = {http://adsabs.harvard.edu/abs/2015MNRAS.453.1619A},
Archiveprefix = {arXiv},
Author = {{Alexeeva}, S.~A. and {Mashonkina}, L.~I.},
Doi = {10.1093/mnras/stv1668},
Eprint = {1507.05446},
Journal = {\mnras},
Keywords = {line: formation, Sun: abundances, stars: abundances, stars: late-type},
Month = oct,
Pages = {1619-1631},
Primaryclass = {astro-ph.SR},
Title = {{Carbon abundances of reference late-type stars from 1D analysis of atomic C I and molecular CH lines}},
Volume = 453,
Year = 2015,
Bdsk-Url-1 = {http://dx.doi.org/10.1093/mnras/stv1668}}

编辑:将所有图片改成源代码。发布代码中使用的“.bib”文件。编辑:根据下面的评论,问题可能是由宏引起的deluxtable,所以我改成deluxtable并重table试,同样的问题出现了。编辑:根据@DavidCarlisle的说法,问题是由aastex6.clsand/or引起的aasjournal.bst\string在前面添加&将解决问题。使用标准 LaTeX 模板不会遇到此问题。此外,许多人建议不要&在引用键中使用,这样你就不会在任何地方遇到问题。

答案1

由于您没有提供示例,所以我没有测试过这一点(但在上面的评论中确认可以工作)。

你可以隐藏&如果你使用

\newcommand\zzzz{{\cite{2007A&A...465..587S}}}

在序言中,然后\zzzz在表格中使用

如果引用在普通文本中有效,那么它也可以在标准乳胶表中工作,因此问题一定出在deluxtable你使用的宏上(但不要使用&引用键,坚持简单[:a-zA-Z0-9]会是个好建议)



CarLaTeX 添加的示例

编辑:这是我用来测试它的 MWE(也许它也适用于deluxtable宏?):

\documentclass[10pt,preprint]{aastex}
\usepackage[english]{babel}
\usepackage{chemformula}
\usepackage{natbib}

\newcommand{\kH}{{\cal H}}
\newcommand\zzzz{{\cite{2007A&A...465..587S}}} 

\begin{document}

\begin{deluxetable}{lll}
\tablecaption{blablabla. \label{tab:bla}}
\tablehead{
\colhead{Species} & \colhead{Model atom} & \colhead{A + \ion{H}{1}}
}
\startdata
\ion{Li}{1} & \zzzz & BB3\\
\ion{C}{1} & \citet{2015MNRAS.453.1619A} & \kH $^1$ = 0.3 \\
\enddata
\tablecomments{blablabla}
\end{deluxetable}

\bibliographystyle{plainnat}
\bibliography{bbb.bib}

\end{document}

这是bbb.bib文件:

@book{2007A&A...465..587S,
  author = {Author, A. and Perche Alsuno},
  year = {2007},
  title = {A duvenen propri vusa kel simbul la},
  publisher = {Publisher},
}

@book{2015MNRAS.453.1619A,
  author = {Alexeeva, A. and Mashonkina, P.},
  year = {2015},
  title = {Keschi l e nurmal},
  publisher = {Publisher},
}

我不知道这与原始命令有多相似,我发明了这个\kH命令,我不知道 OP 是否使用了 natbib 或其他什么,以及使用了哪种风格,但结果是这样的:

enter image description here

答案2

根据比比桌您不应该在引用键中使用 &:

... 字符“ “@',#}{~%”(包括空格字符)是绝对不允许的,而如果你在引用键中使用“&$^”之一,则会收到警告。引用键本质上是 TeX 命令,因此你应该避免使用下划线,例如,如果你需要打印实际的引用键本身。

编辑:根据下面的评论,引用的信息并非 100% 正确。如果我找到更好的,我会发布。

相关内容