【问题标题】:How do I create a huxtable table caption using bookdown in rmarkdown?如何在 rmarkdown 中使用 bookdown 创建一个 huxtable 表格标题?
【发布时间】:2017-09-20 09:45:55
【问题描述】:

我的 rmarkdown 中有许多 huxtable 表。我想使用bookdown 为它们添加字幕。到目前为止,我无法使用“其他 R 包生成表”的 bookdown 说明来执行此操作(请参阅上面的 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。

【问题讨论】:

    标签: r r-markdown bookdown captions


    【解决方案1】:

    已解决。使用set_caption(...) 将标题放入&lt;caption&gt;...&lt;/caption&gt; 元素中,并且不要转义标签:

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

    【讨论】:

      猜你喜欢
      • 2021-05-26
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      相关资源
      最近更新 更多