Home > Software design >  Cross referencing pander-table in rmarkdown
Cross referencing pander-table in rmarkdown

Time:01-14

Despite the huge amount of questions on this subject and despite having read enter image description here

With your table is a same story:

<br>
<div style="text-align: center">
   <caption><span id="tab:c3">Table 3: </span>My table is here</caption>
</div>

<div style="width: 10%; margin: 0 auto;">
```{r c3}
pander(df)
```
</div>

enter image description here


Works everywhere:

```{r c3}
pander(df, caption = "(\\#tab:table-label) Table caption" )
```

pander figure is \@ref(tab:table-label)

CodePudding user response:

Based on @manro's answer, I updated the addlabref-function in my MWE to

addlabref <- function(fcap){

sprintf("(\\#tab:%s) %s", knitr::opts_current$get("label"), fcap)

}

By using knitr::opts_current$get("label"), it keeps the behavior of kable and flextable to use the chunk-name as label. This function can be used to add the label to reference to the pander-caption like

pander( df, caption = addlabref("my caption") )
  •  Tags:  
  • Related