Linked ("clickable") citations within a LaTeX format csas_table() - pbs-assess/csasdown GitHub Wiki
Using Swain and Benoît (2015) as an example (BibTeX code is at the bottom):
Markdown citations render correctly in csas_table()
when using the default settings, i.e. format = “pandoc”
.
The example below produces a pandoc table with a linked citation.
```{r}
d <- data.frame(citation = "@swainbenoit2015")
csasdown::csas_table(d)
```
However, if we have a lot of text in our table and we need the text to wrap, things start to break down.
Markdown citations do not render correctly when format = “latex”
, so we need to embed the link manually.
The example below produces a LaTeX table with a linked citation – if the reference is cited elsewhere in the document.
```{r}
d <- data.frame(abstract = " Improved understanding of the dynamics of populations at low abundance is needed in the face of global biodiversity loss. We examined the dynamics of depleted demersal fish populations in the southern Gulf of St. Lawrence, Canada. Twenty years ago, a number of these populations collapsed due to overexploitation. Since then, others have declined to low abundance. Despite negligible levels of fishing mortality and strong rates of production of small juvenile fish, these populations have shown no sign of recovery and some continue to decline...",
citation = "Swain and Benoît (\\citeproc{ref-swainbenoit2015}{2015})")
csasdown::csas_table(d,
format = "latex",
escape = FALSE) |>
kableExtra::column_spec(1, width = "10cm")
```
If the reference is NOT cited elsewhere in the document, you need to add a no cite option in the metadata field at the top of the RMD file.
---
nocite: |
@swainbenoit2015
---
Bonus:
If you want to include the citation as a footnote instead:
```{r}
d <- data.frame(abstract = " Improved understanding of the dynamics of populations at low abundance is needed in the face of global biodiversity loss. We examined the dynamics of depleted demersal fish populations in the southern Gulf of St. Lawrence, Canada. Twenty years ago, a number of these populations collapsed due to overexploitation. Since then, others have declined to low abundance. Despite negligible levels of fishing mortality and strong rates of production of small juvenile fish, these populations have shown no sign of recovery and some continue to decline...",
citation = "See here\\footnote{Swain and Benoît (\\citeproc{ref-swainbenoit2015}{2015})}")
csasdown::csas_table(d,
format = "latex",
escape = FALSE) |>
kableExtra::column_spec(1, width = "10cm")
```
Note:
If you are reading in .csv (or possibly any other data file), the citations do not need the double backslash, e.g.:
"Swain and Benoît (\citeproc{ref-swainbenoit2015}{2015})"
Here is the BibTeX citation for reproducibility, which goes in the refs.bib file
@article{ swainbenoit2015,
author = {Swain, D.P. and Benoît, H.P.},
title = {Extreme increases in natural mortality prevent recovery of collapsed fish populations in a {N}orthwest {A}tlantic ecosystem},
journal = {Mar. Ecol. Prog. Ser.},
year = {2015},
volume = {519},
pages = {165--182},
doi = {10.3354/meps11012}
}