fig*_*101 4 r tex pandoc r-markdown officer
我正在尝试从 RMarkdown 创建一个 Word 文档 - 到目前为止,一切都很好,除了我必须输出 4 页报告,第一页是纵向,接下来的 2 页 ggplots 是横向的,最后一页是纵向 ggplot。
我已经尝试了所有我能想到的解决方案。我在参考文档中制作了 4 个页面,其中包含我需要的方向,但这不起作用。我还使用包含以下内容的 header.tex 文件尝试了此解决方案:
\usepackage{lscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}
Run Code Online (Sandbox Code Playgroud)
我在 StackOverflow 上看到这个解决方案,使用 pandoc_args 中的 lua 过滤器。
---
title: "Example"
output:
word_document:
pandoc_args:
'--lua-filter=page-break.lua'
---
Run Code Online (Sandbox Code Playgroud)
解决我的问题的解决方案是officedown包中的这个参数: https: //github.com/davidgohel/officedown
<!---BLOCK_LANDSCAPE_START--->
Blah blah blah.
<!---BLOCK_LANDSCAPE_STOP--->
Run Code Online (Sandbox Code Playgroud)
但不幸的是,我无法使用 devtools() 从我需要的工作 RServer 上下载它。有什么方法可以使用和操作office(officedown的非markdown版本)中的某些功能来在我的文档中获得纵向和横向的混合方向?例如,officer包有这个功能: https://github.com/davidgohel/officer/blob/master/R/docx_section.R
body_end_section_landscape <- function( x, w = 21 / 2.54, h = 29.7 / 2.54 ){
w = w * 20 * 72
h = h * 20 * 72
pgsz_str <- "<w:pgSz w:orient=\"landscape\" w:w=\"%.0f\" w:h=\"%.0f\"/>"
pgsz_str <- sprintf(pgsz_str, h, w )
str <- sprintf( "<w:pPr><w:sectPr><w:officersection/>%s</w:sectPr></w:pPr>", pgsz_str)
str <- paste0( wp_ns_yes, str, "</w:p>")
as_xml_document(str)
body_add_xml(x, str = str, pos = "after")
}
#' @export
#' @rdname sections
body_end_section_portrait <- function( x, w = 21 / 2.54, h = 29.7 / 2.54 ){
w = w * 20 * 72
h = h * 20 * 72
pgsz_str <- "<w:pgSz w:orient=\"portrait\" w:w=\"%.0f\" w:h=\"%.0f\"/>"
pgsz_str <- sprintf(pgsz_str, w, h )
str <- sprintf( "<w:pPr><w:sectPr><w:officersection/>%s</w:sectPr></w:pPr>", pgsz_str)
str <- paste0( wp_ns_yes, str, "</w:p>")
body_add_xml(x, str = str, pos = "after")
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
您好,我昨天可以使用该officedown软件包来完成此操作。一旦你安装了它,你就可以去File >New File > RMarkdown选择From Template你可以选择的地方Advanced Word document。他们在模板中为您提供的示例显示了纵向和横向。