I'm encountering a problem using TexShop (with Tex Live 2016 distribution) when try to cite a reference directly in a table. The cite key contains a '&', I guess LaTeX might treat it as a normal tabular separate mark, although it is in the '\citep{}' command. The code is like this:
\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}
Typeset with LaTeX will give you the following error:
./aaa.tex:9: Missing \endcsname inserted.
to be read again
\global
l.9 ...n Failed & {\citet{2007A&A...465..587S}
} & Nothing appears\
?
Meanwhile, the .aux will get a wrong name for '2007A&A...465..587S':
\citation{2007A\global \advance \columncount by 1\relax \saveampersand A...465..587S}
which should be (if you cite this paper in other places of article, only if it's not in a table):
\citation{2007A&A...465..587S}
Using this incorrect .aux file, BibTeX will tell you:
White space in argument---line 19 of file aaa.aux
: \citation{2007A\global
: \advance \columncount by 1\relax \saveampersand A...465..587S}
I'm skipping whatever remains of this command
Finally, the citation won't appear in the .pdf file, as a contrast, the second paper cited in the table will appear, like this:
Yes, I can change the cite key by deleting '&' and then problem solved, but I'm trying to figure out how to solve the problem without changing cite key, because the cite key is usually generated automatically by other tools, and it is not a easy task to change all the cite keys of such type.
The 'bbb.bib' used in this example is:
@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}}
EDIT: Change all the pictures into source code. Posted the '.bib' file used in the code.
EDIT: According to the comments below, the problem might be caused by the deluxtable
macro, so I changed deluxtable
into table
and tried again, same problem occurred.
EDIT: According to @DavidCarlisle, The problem is caused by aastex6.cls
and/or aasjournal.bst
. Add \string
before &
will solve the problem. You won't meet this problem using standard LaTeX template. Also, many people suggest simply do NOT use &
in the cite keys, so that you won't meet the problem anywhere.
{}
. This way people can copy and paste your code into their own documents and test it and try to fix your problem. It makes it much easier for people to hep you and hence m much more likely that some one will. This said, it is also better to post a full minimal working example of compilable code and, in your case, a bibtex entry.\newcommand\zzzz{{\cite{2007A&A...465..587S}}
in the preamble, and then used\zzzz
in the table.