gpt4 book ai didi

r - 从 RMarkdown 生成 Word 文档时混合横向 + 纵向页面

转载 作者:行者123 更新时间:2023-12-04 17:29:16 28 4
gpt4 key购买 nike

我正在尝试从 RMarkdown 创建一个 word 文档 - 到目前为止一切都很好,除了我必须输出一个 4 页的报告,第一页是肖像,接下来的两页 ggplots 是横向的,最后一页是ggplot 纵向。

我已经尝试了我能想到的所有解决方案。我在引用 docx 中制作了 4 页,其中包含我需要的方向,但这没有用。我也试过 this solution使用包含以下内容的 header.tex 文件:

\usepackage{lscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}

this solution我在 StackOverflow 上看到在 pandoc_args 中使用 lua 过滤器。
---
title: "Example"
output:
word_document:
pandoc_args:
'--lua-filter=page-break.lua'
---

可以解决我的问题的解决方案是 officedown 包中的这个参数: https://github.com/davidgohel/officedown
<!---BLOCK_LANDSCAPE_START--->

Blah blah blah.

<!---BLOCK_LANDSCAPE_STOP--->

但不幸的是,我无法在我需要的工作 RServer 上使用 devtools() 下载它。有什么方法可以使用和操作官员(officedown 的非 Markdown 版本)中的某些功能来在我的文档中混合纵向和横向方向?比如官员包有这个功能:
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")
}

谢谢!

最佳答案

您好,我昨天可以使用 officedown 做到这一点包裹。一旦你安装它你可以去File >New File > RMarkdown并选择 From Template您可以在这里选择 Advanced Word document .他们在模板中为您提供的示例同时显示了纵向和横向。

关于r - 从 RMarkdown 生成 Word 文档时混合横向 + 纵向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61152361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com