我的rmarkdown中有很多huxtable个表格。我想使用bookdown标题。到目前为止,我还没有使用其他R套餐的预订说明生成表格" (见上面的URL)。
此处的示例遵循this answer中的说明:
---
title: "huxtable-mwe"
site: bookdown::bookdown_site
output:
bookdown::html_book
documentclass: book
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(huxtable)
library(magrittr)
```
See table \@ref(tab:bar).
Table (\#tab:foo): Foo
```{r foo, echo=FALSE}
ht <- hux(
foo = c('foo','bar')
) %>%
set_all_borders(1)
ht
```
See table \@ref(tab:foo).
Table (\#tab:bar): Bar
```{r bar, echo=FALSE}
ht <- hux(
foo = c('bar', 'baz')
) %>%
set_all_borders(1)
ht
```
引用有效,但我得到以下表格标题:
表(#tab:foo):Foo
表(#tab:bar):栏
我的预期:
表1:Foo
表2:栏
感谢MWE。
答案 0 :(得分:1)
解决。使用set_caption(...)
将标题添加到<caption>...</caption>
元素中,并且不要转义标签:
---
title: "huxtable-mwe"
site: bookdown::bookdown_site
output:
bookdown::html_book
documentclass: book
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(huxtable)
library(magrittr)
```
See table \@ref(tab:bar).
```{r foo, echo=FALSE}
ht <- hux(
foo = c('foo','bar')
) %>%
set_all_borders(1) %>%
set_caption('(#tab:foo) Foo')
ht
```
See table \@ref(tab:foo).
```{r bar, echo=FALSE}
ht <- hux(
foo = c('bar', 'baz')
) %>%
set_all_borders(1) %>%
set_caption('(#tab:bar) Bar')
ht
```