如何在 rmarkdown 中使用 bookdown 创建 huxtable 表标题? [英] How do I create a huxtable table caption using bookdown in rmarkdown?

查看:49
本文介绍了如何在 rmarkdown 中使用 bookdown 创建 huxtable 表标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 rmarkdown 中有许多 huxtable 表.我想使用 bookdown 为它们添加标题.到目前为止,我一直无法使用其他 R 包生成表格"的 bookdown 说明来执行此操作(请参阅上面的 URL).

I have numerous huxtable tables in my rmarkdown. I'd like to caption them using bookdown. So far I've been unable to do this using the bookdown instructions for "other R packages to generate tables" (see URL above).

这是一个示例,它遵循此答案中的说明:

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:

表 (#tab:foo): Foo

Table (#tab:foo): Foo

表格(#tab:bar):条形

Table (#tab:bar): Bar

在我预期的时候:

表 1:Foo

表 2:条形

感谢 MWE.

推荐答案

已解决.使用 set_caption(...) 将标题放入 <caption>...</caption> 元素,并且不要对标签进行转义:

Resolved. Use set_caption(...) to get the caption into a <caption>...</caption> element, and don't escape the label:

---
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
```

这篇关于如何在 rmarkdown 中使用 bookdown 创建 huxtable 表标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆