# Citations in tabular environment not working

I'm writing my thesis with Rmarkdown but with a lot of LaTeX mixed in. When I compile the document, all my citations appear just fine, but those in my table appear as [?]. I have tested different types of tables, but even a very simple table does not manage to show the citations:

---
bibliography: library.bib
csl: conservation-biology.csl
output: pdf_document
---

\begin{center}
\begin{tabular}{ c c c }
cell1 & cell2 & \cite{Saunders2007} \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
\end{center}


I have also tried Rmarkdown's citing format instead of \cite{}: [@Saunders2007], but that shows up unformatted.

Am I missing something that should be done when citing inside tables?

• rosannav, Can you answer your question? how did you solve it? Jan 26, 2016 at 21:46

The table is based on LaTeX. Using Rmarkdown inside the table environment is never going to work, as it doesn't recognise Rmarkdown. Using LaTeX citations is logical idea, however, LaTeX citations don't work the same way Rmarkdown citations work. This is an Rmarkdown document and doesn't provide any instructions for LaTeXtables. As you can see, the YAML header provides Rmarkdown citation instructions:

---
bibliography: library.bib
csl: conservation-biology.csl
---


With the bibliography file (.bib) and citation style (.csl) specified. The citations are read by pandoc (that's what knitr uses to convert .rmd files to .md files) and turned into plain text in the .md file. To get a latex/pdf document, the .md file is further converted to a .tex file using pdflatex. The Rmarkdown citation [@Saunders2007] is now written plain text.

It is better to use the LaTeX citation \cite{Saunders2007} instead, as this will be recognized as LaTeX and therefore LaTeX will try to look up the citation. However, no reference library is given for LaTeXcitations. To do this, one needs to write \bibliography{library}{} at the bottom of the document.

However, we want the citation styles to be the same. I'm using conservation-biology.csl here. Unfortunately, latex/bibtex doesn't use .csl files but .bst files (using \bibliographystyle{stylename} at the bottom of the document). As there are way more .csl files than .bst available (check this massive .csl repo), it's unlikely that your specific Rmarkdown citation style can also be found as .bst file.

Of course, you can write your own .bst file, but for the number of citations that are contained in the table it might be easier to just hand write them. To make sure they appear in the references list, use this:

---
nocite: |
@Saunders2007
...


It is also possible to create the table in markdown directly for pandoc to cite the reference.

---
bibliography: library.bib
csl: conservation-biology.csl
output: pdf_document
---

| col1  | col2  | ref           |
|-------|-------|---------------|
| cell1 | cell2 | @Saunders2007 |
| cell4 | cell5 | cell6         |
| cell7 | cell8 | cell9         |

• Could you please elaborate, wouldn't an other question be a duplicate ?Also, IMHO, the 2 other answers are work-around. Mar 24, 2018 at 16:19

In Rmarkdown citations are generated with pandoc. So it won't recognize a 'Latex-citation' style ad-hoc. In your table, you are in an Latex environment so Pandoc citation style are not recognized either...

There is surely a way to implement it directly in Rstudio but to understand your problem you could add the option keep_tex in the yaml preamble and add call BibTeX at the end

---
output:
pdf_document:
keep_tex: yes
---

\begin{center}
\begin{tabular}{ c c c }
cell1 & cell2 & \cite{Saunders2007} \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
\end{center}

\bibliographystyle{chicago}
\bibliography{library.bib}


Compile the Rmd to generated the .tex file and then this .tex file with pdflatex. That should work