我想生成以下屏幕截图。简而言之,应将“ Hello World”放置在“图1”标题下,将“晚安世界”放置在“图2”标题下。取而代之的是,我得到了与两个短语相关的两个标题。
library(officer)
library(magrittr)
library(flextable)
my_doc2 <- read_docx()
n=2
bl=c('1','2','3')
b2=c('1','2')
for(j in 1:n){
for( i in 1:(length(bl))){
my_doc2 <- my_doc2 %>%
body_add_par(paste0("Figure",j), style = "graphic title") %>%
body_add_par(paste0("Hello world",i), style = "Normal")
}
for( i in 1:(length(b2))){
my_doc2 <- my_doc2 %>%
body_add_par(paste0("Figure",j), style = "graphic title") %>%
body_add_par(paste0("Goodnight world",i), style = "Normal")
}
}
#writing to word file
print(my_doc2, target = "second_example.docx")