John Smith
John Smith

Reputation: 2886

Referencing a simple table in RMarkdown

I have a table in RMarkdown that i want to reference

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1

Table:  Demonstration of simple table syntax.

Can anyone tell me how to reference it. So basically i want to say Please see table 1.1 for more detail

Upvotes: 4

Views: 982

Answers (1)

scoa
scoa

Reputation: 19867

A solution that does not depend on output format is the pandoc-crossref filter. Whenever you output a table, add a reference to its caption (here with pander):

```{r}
library(pander)
tb <- table(sample(letters[1:4], 10, replace=TRUE))
pander(tb, caption= "my table {#tbl:mytable}")
```

Then you can reference this table with:

see [@tbl:mytable] for more details

To run the filter, add this to your YAML front matter:

---
output:
  pdf_document:
    pandoc_args: ["-F=pandoc-crossref"]
---

Pandoc-crossref can be installed with its binaries or through the haskell platform. In the latter case:

cabal update
cabal install pandoc-crossref

Upvotes: 3

Related Questions