我觉得我错过了一些简单的东西。手指交叉就是这样。
我试图在 officedown 中使用 gtsummary 和 flextable 制作表格。我正在使用 officedown 中“高级 word 文档”模板中的 yaml 选项。
下面是我的代码。前两张桌子下面有标题,第三张在上面,应该是这样!
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)
library(officedown)
library(officer)
library(palmerpenguins)
library(gtsummary)
library(tidyverse)
library(flextable)
```
## My tables
```{r,tab.id="peng" }
penguins %>%
tbl_summary(by=species) %>%
as_flex_table() %>%
set_caption("Flextable Caption by set_caption")
```
```{r,tab.id="peng2", tab.cap="Caption by knitr" }
penguins %>%
tbl_summary(by=species) %>%
as_flex_table()
```
### Tables from example
```{r tab.cap="caption 1", tab.id="mtcars"}
head(mtcars)
```
## 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)!)