[英]How do I create a huxtable table caption using bookdown in rmarkdown?
I have numerous huxtable tables in my rmarkdown. 我的rmarkdown中有很多huxtable表。 I'd like to caption them using bookdown . 我想用bookdown给他们加上标题。 So far I've been unable to do this using the bookdown instructions for "other R packages to generate tables" (see URL above). 到目前为止,我无法使用“其他用于生成表的R包”的预订说明来执行此操作(请参见上面的URL)。
Here's an example which follows the instructions in 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
```
References work, but I get the following table captions: 参考有效,但获得以下表格标题:
Table (#tab:foo): Foo 表格(#tab:foo):Foo
Table (#tab:bar): Bar 表格(#tab:bar):栏
when I expected: 当我期望:
Table 1: Foo 表1:Foo
Table 2: Bar 表2:栏
Grateful for a MWE. 感谢MWE。
Resolved. 解决。 Use set_caption(...)
to get the caption into a <caption>...</caption>
element, and don't escape the label: 使用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
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.