使用R中的officer
包时,使用PowerPoint时,您可以使用函数ph_with_text
添加文本。但是,目前尚不清楚如何添加多个文本项目符号或如何设置缩进级别。我想实现以下结构:
我尝试过两种方法都会产生非常错误的结果。我尝试使用我的文字并添加\n
和\n\t
来创建换行符和标签页(就像我将如何在PowerPoint中创建结构一样。
doc = read_pptx()
doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body",
str = "Question 1\n\tAnswer 1\n\tAnswer 2\nQuestion 2\n\tAnswer 1\n\tAnswer 2",
index = 1)
这会产生子弹,但不会产生深度。在每个答案之前,每个项目符号后面都有一个空白选项卡。此外,这些不是新的项目符号,如果我手动编辑文件并按下一个项目符号上的选项卡,之后的每个点也会移动。显然,没有实现正确的结构。
我也尝试过反复调用ph_with_text
。
doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body", str = "Question 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Question 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)
但是这最终将文本覆盖在同一条线上,这是一个难以理解的混乱。
如何通过officer
向幻灯片添加文本以实现多个项目符号和缩进子元素?
答案 0 :(得分:5)
函数ph_with_ul
是您需要的功能
library(magrittr)
pptx <- read_pptx()
pptx <- add_slide(x = pptx, layout = "Title and Content", master = "Office Theme")
pptx <- ph_with_text(x = pptx, type = "title", str = "Example title")
pptx <- ph_with_ul(
x = pptx, type = "body", index = 1,
str_list = c("Level1", "Level2", "Level2", "Level3", "Level3", "Level1"),
level_list = c(1, 2, 2, 3, 3, 1),
style = fp_text(color = "red", font.size = 0) )
print(pptx, target = "example2.pptx")