Tuesday, February 12, 2019

Table References in R Markdown to PDF

This is just a quick post for my own sanity. I spent a fairly decent amount of time trying to figure out how to reference tables in an RMarkdown document when outputting to PDF. For the record, I'm loading the booktabs and float packages in LaTeX (via the YAML header) and kable in R.

The trick that seemed to work is to put the LaTeX label as part of the kable argument: caption="\\label{tab:tabname}Caption text". The table can then be referred to in the text with \ref{tab:tabname}.

I'm sure that there are more elegant ways than this, but this seemed to get me what I needed for now.

No comments: