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

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

问题描述

我正在玩解决方案

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

-reference-docx = 文件

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

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

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


选项1(无法解决页面方向问题):

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

选项#2(看起来很优雅,但尚未经过测试):

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

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

Optin#3(在Word中几次点击可能会完成):

由于您可能会花费大量时间来设置如何插入节以及正确的大小,边距,并弄清楚如何使表格适合这样的布局……我建议您使用pandoc进行写入您在Word中打开的document.docx,并手动进行布局:

  • 在横向页面上选择所需的表格
  • 转到布局>边距
    > 选择应用于:所选文本
    > 选择页面设置> 选择横向

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

无论如何,您可能还想做的就是对表格和表格标题进行一些样式设置(字体大小,...),以达到最佳效果(所有文本样式都可以使用pandoc进行应用,其中--reference-docx派上用场).

选项4(在您只能使用pdf而不是docx的情况下):

据我所知,pandoc在md -> docx中的表(对齐,样式,...)上做得很好,在tex -> docx中有时会遇到一些麻烦.但是,如果您的选择允许 pdf 输出乳胶,则将是您最好的朋友.例如,您的问题就像使用

一样容易解决

\usepackage{pdflscape}

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

\begin{landscape}
...
\end{landscape}

这是我到目前为止可以想到的选项.

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

但是,我也知道,由于各种原因,单词文档仍然是许多领域中审阅手稿的主要方式...所以我很可能会选择我建议的选项3,主要是因为这是一种懒惰且快速的解决方案而且因为我通常没有太多带有笨拙的放置和样式的巨型桌子的文档.

祝你好运;-)

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.

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?

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.

解决方案

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:

--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.

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.

The docx writer builds by default a continuous document, with elements such as headers, paragraphs, simple tables and so on ... much like a html output.


Option #1 (doesn't solve the page orientation problem):

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

Option #2 (seems elegant but hasn't been tested):

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.

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.

Optin #3 (a couple of clicks in Word might just do):

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.

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).

Option #4 (in situation when you can just use pdf instead of docx):

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

\begin{landscape}
...
\end{landscape}

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

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.

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.

Good luck ;-)

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

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