首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在officedown中使用gt汇总+ flextable,则表标题在表下面

如果在officedown中使用gt汇总+ flextable,则表标题在表下面
EN

Stack Overflow用户
提问于 2021-12-15 05:25:00
回答 1查看 380关注 0票数 1

我觉得我错过了一些轻松的东西。祝你好运吧。

我试图在officedown中使用gt汇总和可弯曲的方法来生成表。我正在使用officedown中“高级word文档”模板中的yaml选项。

下面是我的密码。前两个表有下面的标题,第三个表在顶部,这是应该的!

代码语言:javascript
复制
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] flextable_0.6.10     forcats_0.5.1        stringr_1.4.0       
 [4] dplyr_1.0.7          purrr_0.3.4          readr_2.0.2         
 [7] tidyr_1.1.4          tibble_3.1.5         ggplot2_3.3.5       
[10] tidyverse_1.3.1      gtsummary_1.5.0      palmerpenguins_0.1.0
[13] janitor_2.1.0        officer_0.4.1        officedown_0.2.3    


---
date:  "Last compiled on `r format(Sys.time(), '%d %B, %Y')`"
author: "Kristy Robledo"
title: "Table captions example"
output: 
  officedown::rdocx_document:
    mapstyles:
      Normal: ['First Paragraph']
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = FALSE,fig.cap = TRUE)

图书馆(办公大楼)

图书馆(主任)

图书馆(掌企鹅)

图书馆(gtsummary摘要)

图书馆(Tidyverse)

图书馆(可弯曲)

代码语言:javascript
复制
## My tables

```{r,tab.id="peng" }

企鹅%>%

tbl_summary(by=species) %>%

as_flex_table() %>%

Set_caption(“set_caption提供的可伸缩标题”)

代码语言:javascript
复制
```{r,tab.id="peng2", tab.cap="Caption by knitr" }

企鹅%>%

tbl_summary(by=species) %>%

as_flex_table()

代码语言:javascript
复制
### Tables from example

```{r tab.cap="caption 1", tab.id="mtcars"}

磁头(地铁)

代码语言:javascript
复制
## Reference

see  table \@ref(tab:mtcars) for how I want it and these tables for underneath! 
(table \@ref(tab:peng) and  table \@ref(tab:peng2)!)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-15 08:35:37

不是flextableofficedown方面的专家。但是,对我有用的一种选择是通过以下方式设置R标记文档表标题的位置

knitr::opts_chunk$set(tab.topcaption = TRUE)

完全可复制代码:

代码语言:javascript
复制
---
date:  "Last compiled on `r format(Sys.time(), '%d %B, %Y')`"
author: "Kristy Robledo"
title: "Table captions example"
output: 
  officedown::rdocx_document:
    mapstyles:
      Normal: ['First Paragraph']
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = FALSE,fig.cap = TRUE)

图书馆(办公大楼)

图书馆(主任)

图书馆(掌企鹅)

图书馆(gtsummary摘要)

图书馆(Tidyverse)

图书馆(可弯曲)

代码语言:javascript
复制
```{r}

knitr::opts_chunk$set(tab.topcaption = TRUE)

代码语言:javascript
复制
## My tables

```{r,tab.id="peng" }

企鹅%>%

tbl_summary(by=species) %>%

as_flex_table() %>%

Set_caption(“set_caption提供的可伸缩标题”)

代码语言:javascript
复制
```{r, tab.id="peng2", tab.cap="Caption by knitr"}

企鹅%>%

tbl_summary(by=species) %>%

as_flex_table()

代码语言:javascript
复制
### Tables from example

```{r tab.cap="caption 1", tab.id="mtcars"}

磁头(地铁)

代码语言:javascript
复制
## Reference

see  table \@ref(tab:mtcars) for how I want it and these tables for underneath! 
(table \@ref(tab:peng) and  table \@ref(tab:peng2)!)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70358796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档