是否有控制输出页面方向的选项(使用 knitr->pander->pandoc->docx) [英] Is there an option to control output page orientation (using knitr->pander->pandoc->docx)

查看:17
本文介绍了是否有控制输出页面方向的选项(使用 knitr->pander->pandoc->docx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 Tal 的 介绍如何在现实世界中以尽可能少的开销生成单词表.(请参阅那里的可重现示例 - 谢谢,Tal!)在实际应用中,表格很宽,无法在纵向页面上打印,但您可能不想拆分它们.

I am playing with Tal's intro to producing word tables with as little overhead as possible in real world situations. (Please see for reproducible examples there - Thanks, Tal!) In real application, tables are to wide to print them on a portrait-oriented page, but you might not want to split them.

抱歉,如果我在 pandoc 或 pander 文档中忽略了这一点,但是从 R 写入 Word .docx 文件时如何控制页面方向(纵向/横向)?

Sorry if I have overlooked this in the pandoc or pander documentation, but how do I control page orientation (portrait/landscape) when writing from R to a Word .docx file?

我也许应该补充一下,我开始使用 knitr+markdown,但我还不熟悉 LaTex 语法.但我会在完成工作的同时尽可能多地收拾东西.

I maybe should add tat I started using knitr+markdown, and I am not yet familiar with LaTex syntax. But I'm trying to pick up as much as possible while getting my stuff done.

推荐答案

我很确定 docx writer 没有实现分节符,据我所知 --reference-docx 允许自定义样式而不是页面布局(但我在这里也可能是错的),这是来自 --reference-docx 上的 pandocs 指南:

I am pretty sure the docx writer has no section breaks implemented, also as far as I understand --reference-docx allows for customizing styles and not the page layout (but I might also be wrong here), this is from pandocs guide on --reference-docx:

在生成 docx 文件时使用指定的文件作为样式参考.为获得最佳结果,参考 docx 应为使用 pandoc 生成的 docx 文件.参考docx的内容被忽略,但它的样式表在新的 docx 中使用.如果不命令行中指定了reference docx,pandoc会查找用户数据目录中的文件 reference.docx(请参阅 --data-dir).如果这也没有找到,将使用合理的默认值.这pandoc 使用以下样式:[段落] 正常、标题、作者,日期,标题 1,标题 2,标题 3,标题 4,标题 5,块引用、定义术语、定义、正文、表格标题、图片说明;[字符] 默认段落字体、正文字符、逐字字符、脚注参考、链接.

--reference-docx=FILE

Use the specified file as a style reference in producing a docx file. For best results, the reference docx should be a modified version of a docx file produced using pandoc. The contents of the reference docx are ignored, but its stylesheets are used in the new docx. If no reference docx is specified on the command line, pandoc will look for a file reference.docx in the user data directory (see --data-dir). If this is not found either, sensible defaults will be used. The following styles are used by pandoc: [paragraph] Normal, Title, Authors, Date, Heading 1, Heading 2, Heading 3, Heading 4, Heading 5, Block Quote, Definition Term, Definition, Body Text, Table Caption, Image Caption; [character] Default Paragraph Font, Body Text Char, Verbatim Char, Footnote Ref, Link.

哪些是保存在 docx 文档的 /word/styles.xml 组件中的样式.另一方面,页面布局保存在 <w:sectPr> 标签中的 /word/document.xml 组件中,但是 pandoc 的 docx writer 忽略了这部分作为据我所知.

Which are styles that are saved in the /word/styles.xml component of the docx document. The page layout on the other hand is saved in the /word/document.xml component in the <w:sectPr> tag, but pandoc's docx writer ignores this part as far as I can tell.

默认情况下,docx 编写器会构建一个连续的文档,其中包含标题、段落、简单表格等元素……很像 html 输出.

您可以通过样式定义的唯一页面布局选项是 pageBreakBefore,它将在特定样式之前添加分页符

The only page layout option that you can define through styles is the pageBreakBefore which will add a page break before a certain style

最近添加了允许自定义 lua 脚本的 自定义 编写器,您应该能够在其中定义某些 Pandoc 块将如何写入输出文件...这意味着您可以为将 sectPr 标签插入文档的特定块定义分节符和页面布局.我还没有尝试过这个,但值得研究.在 pandoc github 上,您可以查看自定义 html 输出的示例 lua 脚本文件.

Recently the custom writer has been added that allows for a custom lua script, where you should be able to define how certain Pandoc blocks will be written into the output file ... meaning you could potentially define section breaks and page layout for a specific block inserting the sectPr tag into the document. I haven't tried this out but it would be worth investigating. On pandoc github you can check out a sample lua script file for custom html output.

然而,这意味着你必须安装 lua,学习语言,如果你认为值得花时间投资,这取决于你.

However, this means, you have to have lua installed, learn the language, and it is up to you if you think its worth the time investment.

因为您可能会花费相当多的时间来设置如何插入部分以及正确的大小、边距以及如何使表格适合这种布局......我建议您使用 pandoc 来放置 write您在 Word 中打开的 document.docx,并手动进行布局:

As you will probably spend quite some time setting up how to insert sections and what would be the right size, margins, and figuring how to fit the table to such a layout ... I recommend that you use pandoc to put write your document.docx, that you open in Word, and do the layout by hand:

  • 在横向页面上选择您想要的表格
  • 转到布局>边距
    > 选择应用于:所选文本
    >选择页面设置>选择横向
  • select the table you want on the landscape page
  • go to Layout > Margins
    > select Apply to: Selected text
    > choose Page Setup > select Landscape

现在,您的桌子周围应该有一个横向的新部分.

Now a new section with a landscape orientation should surround your table.

无论如何,您可能还想做的是对表格和表格标题做一点样式(字体大小,...),以达到最佳效果(所有文本样式都可以通过 pandoc 应用,其中 --reference-docx 很方便).

What you would anyway also probably want to do is styling the table and table caption a little (font-size,...), to achieve the best result (all text styling can be already applied with pandoc where --reference-docx comes handy).

据我所知,pandoc 可以很好地处理 md -> 中的表格.docx (alignment, style, ... ), in tex ->docx 有时会遇到一些麻烦.但是,如果您的选项允许 pdf 输出,乳胶将是您最好的朋友.例如,您的问题就像使用

As far as I could figure out is that with pandoc does a good job with tables in md -> docx (alignment, style, ... ), in tex -> docx it had some trouble sometimes. However if your option allows for a pdf output latex will be your greatest friend. For example your problem is solved as easily as just using

usepackage{pdflscape}

并将其添加到您的桌子周围

and adding this around your table

egin{landscape}
...
end{landscape}

这是我目前能想到的选项.

This are the options that I could think of so far.

我始终建议使用 pdf 格式的报告,因为您可以使用 Latex 根据自己的喜好设置样式,并且布局将保持您想要的样子.

I would always recommend using the pdf format for reports, as you can style it to your liking with latex and the layout will stay the way you want it to be.

但是,我也知道由于各种原因,word 文档仍然是许多领域审稿的主要方式……所以我很可能只使用我建议的选项 3,主要是因为它是一种懒惰且快速的解决方案并且因为我通常没有很多文档,其中包含大量放置和样式笨拙的巨型表格.

However, I also know that for various reasons word documents are still the main way of reviewing manuscripts in many fields ... so i would most likely just go with my suggested option 3, mostly cause it is a lazy and quick solution and because I usually don't have many documents with tons of giant tables with awkward placement and styling.

祝你好运;-)

这篇关于是否有控制输出页面方向的选项(使用 knitr->pander->pandoc->docx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆