简体   繁体   中英

r knitr Pandoc latex

I'm using the knitr package to make a table in PDF that I want to refer to within the document eg

\ref{table:name} on page \pageref{table:name} 

Below is a sample of the function but I have trouble inserting a table's label

knitr::kable(head(iris), format = "latex")

In a latex document the command is like the one below

\label{table:name}

Is there a way to insert a label into a kable?

This is my solution

```{r, echo=FALSE}
library(captioner)
library(stringr)
table_nums <- captioner(prefix = "Table")
f.ref <- function(x){stringr::str_extract(table_nums(x), "[^:]*")}
```

```{r table1}
tab.1_cap <- table_nums(name = "tab_1")
knitr::kable(head(iris), caption = "Header data iris.")
```

Ahora podemos observar los datos de la base iris en la. Use `` inside this code r f.ref("tab_1") to run r codes within text in rmarkdown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM