如何使用ReporteRs在* .docx文件中添加没有任何编号的脚注?

时间:2017-10-21 20:27:24

标签: r reporters footnotes

使用ReporteRs包时,似乎将文本放入页面页脚的唯一方法是在文本正文中放置一个带编号的脚注,并使该脚注显示为相同的数字页脚。我希望能够将文本放在页面的页脚中而不需要任何编号。

library(ReporteRs)

doc1 <- docx()
doc1 <- addFlexTable(doc1,vanilla.table(head(iris)))
Foot <- Footnote()
Foot <- addParagraph(Foot,"This should not have a number in front of it")
doc <- addParagraph(doc,pot("There should be no number after this",footnote=Foot))
writeDoc(doc1, file = "footnote1.docx")

或者,如果可以在页面底部放置一个段落,那也可以解决我的问题。这可以通过确定页面上可以容纳多少行来完成,但是如果有某种方法可以将垂直对齐方式作为最后一段的页面底部,那将是理想的。

doc2 <- docx()
doc2 <- addFlexTable(doc2,vanilla.table(head(iris)))
doc2 <- addParagraph(doc2,c(rep("",33),"Text placed by dynamically finding bottom of the page"))
writeDoc(doc2, file = "footnote2.docx")

1 个答案:

答案 0 :(得分:1)

您尝试执行的操作与编写的ReporteRs::Footnote不符,如帮助中所示:

  

如果在docx对象中,脚注将被紧跟在注释引用的文本部分之后的数字标记。

但是,如果我正确理解你的问题,你所追求的是可以实现的。表格中的注释和页脚中的文本不会以任何方式连接,例如Footnote提供的超链接。

还有一个问题是ReporteRs没有提供在不使用书签的情况下在页脚中放置文字的方法(Footnote除外,我们现在已经打折)。这意味着我们需要使用 docx 模板而不是包生成的空文档。

模板创建

步骤:

  1. 来自 MS Word 我已打开一个空文档
  2. 将光标放在页脚区域
  3. 插入=&gt;书签
  4. 输入书签名称,我刚使用FOOTER,然后点击添加
  5. 保存文档
  6. enter image description here

    使用ReporteRs

    生成文档

    使用我们的新模板,接下来的步骤似乎更为熟悉。

    library(ReporteRs)
    
    doc <- docx(template = "Doc1.docx")
    
    # do the flextable, note that I add your table footer here
    ftable <- vanilla.table(head(iris))
    
    ftable <- addFooterRow(
      ftable,
      value = c("There should be no number after this"),
      colspan = 5
    )
    
    doc <- addFlexTable(doc, ftable)
    
    # check for the presence of our bookmark
    list_bookmarks(doc)
    # [1] "FOOTER"
    
    # now add the footer text using the bookmark
    doc <- addParagraph(
      doc, stylename = "footer", bookmark = "FOOTER",
      pot("This should not have a number in front of it")
    )
    
    # and finally write the document
    writeDoc(doc, file = "doc.docx")
    

    最终产品

    该表格,您可以更好地格式化以适应,我没有删除添加的行上的边框。

    enter image description here

    标准页脚样式的页脚,您可以再次修改以适应。

    enter image description here