简体   繁体   English

如何在rmarkdown中使用bookdown创建一个huxtable表标题?

[英]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.

相关问题 在 Rmarkdown 中使用 pandoc 和 bookdown 时如何删除图形标题中的冒号? - How remove colon in figure caption when using pandoc and bookdown in Rmarkdown? 如何为bookdown / rmarkdown网站重新缩放本地图像? - How do I rescale local images for bookdown / rmarkdown website? 如何在Rmarkdown bookdown pdf:document2中的图形标题中获取换行符 - How to get a newline in a figure caption in Rmarkdown bookdown pdf:document2 在 RMarkdown 中为 PDF 使用 huxtable 标签 - Using huxtable labels in RMarkdown for PDF 如何在 r markdown 和 bookdown 中的图形标题下方创建图形注释 - How to create a figure note below the figure caption in r markdown and bookdown 如何使用 R 中的“huxtable”库为表格中所需的单元格着色。 哪种方式更优雅? - How to color the required cells in the table using "huxtable" library in R. Which is more elegant way to do it? 如何使用 bookdown 更改 RMarkdown 中表格标题中的前缀词和分隔符? - How to change the prefix word and separator in table captions in RMarkdown with bookdown? 如何使用huxtable()在小标题中使用回归模型的打印列表列 - How do I use print list-column of regression models in a tibble using huxtable() R 的 Huxtable 包:如何在 bookdown 中正确引用 huxtables? - Huxtable package for R: How to correctly reference huxtables in bookdown? 如何使用 rmarkdown 为报表创建自定义表格? - how to create a customized table for report using rmarkdown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM