简体   繁体   English

Pandoc输出中的表格或图像太宽,如DOCX或PDF / LaTeX

[英]Tables or images too wide in Pandoc output as DOCX or PDF/LaTeX

I am writing a quick and dirty report using pandoc and markdown. 我正在使用pandoc和markdown写一个快速而肮脏的报告。

I need to generate a PDF or a DOCX with minimum hassle, I don't care much about which (best would be both, of course). 我需要以最小的麻烦生成PDF或DOCX,我不在乎哪个(当然最好是两者)。 Also, I am somewhat constrained regarding the figures and tables -- they have been generated a priori with another program and I would rather be able to insert them as they are then to convert them to suit pandoc's needs. 此外,我对数字和表格有一定的限制 - 它们已经与另一个程序先验地生成,我宁愿能够插入它们,因为它们将它们转换为适合pandoc的需要。

However, the main constraint is that I don't want to edit the resulting document manually, be that LaTeX or DOCX. 但是,主要的限制是我不想手动编辑生成的文档,无论是LaTeX还是DOCX。 I want to do all editing in markdown. 我想在降价时进行所有编辑。

Here is the problem: 这是问题所在:

  • In DOCX, the tables are displayed fine: they have the width of the document. 在DOCX中,表格显示正常:它们具有文档的宽度。 However, the figures are much too wide. 但是,这些数字太宽了。 I can either convert the images to a lower resolution (which doesn't look nice), or manually resize the images in Word (which is out of question). 我可以将图像转换为较低的分辨率(看起来不太好),或者手动调整Word中的图像大小(这是不可能的)。
  • In PDF, the generated figures are fine (more or less), however another two problems appear: 在PDF中,生成的数字很好(或多或少),但是会出现另外两个问题:
    • The tables are too wide, because there are no line breaks, and 表格太宽,因为没有换行符,而且
    • LaTeX being LaTeX, the order of figures and tables are "reorganized", that is, they are not consecutive. LaTeX是LaTeX,数字和表格的顺序是“重组”的,也就是说,它们不是连续的。

Thus, none of the documents generated are usable for my purposes. 因此,生成的文档都不能用于我的目的。

All I wanted to do is to slap together some results and generate a file that I can send to another scientist. 我想做的就是将一些结果拼凑在一起并生成一个我可以发送给另一位科学家的文件。

Question: what is the best solution to generate a quick and dirty report in pandoc with minimum effort and at least all results visible? 问题:在pandoc中以最小的努力生成快速而脏的报告的最佳解决方案是什么,并且至少可以看到所有结果?

Update: Upgrading pandoc to 1.4 or later solves the issue -- the figures have now correct sizes in docx documents. 更新:将pandoc升级到1.4或更高版本可以解决问题 - 这些数字现在在docx文档中具有正确的大小。

Control over image size 控制图像大小

Currently you cannot control that feature directly from Markdown. 目前,您无法直接从Markdown控制该功能。 For LaTeX/PDF output, this is automatically handled by LaTeX/pdflatex itself. 对于LaTeX / PDF输出,这由LaTeX / pdflatex本身自动处理。

In recent months there have been some discussions going on in the Pandoc developer + user community about how to best implement it and create an easy-to-use syntax, for example 最近几个月,Pandoc开发人员和用户社区一直在讨论如何最好地实现它并创建一个易于使用的语法,例如

![Image Caption](./path/to/image.jpg "Image Comment"){width="60%", height="150px"}

( Warning: Example only, made up on the spot + extracted from thin air by myself -- can't remember the latest state of the discussion...) This is designed to then transfer to all the supported output formats which can contain images, not just to LaTeX/PDF. 警告:仅限示例,由现场制作+由我自己从空气中提取 - 无法记住讨论的最新状态...)这是为了转移到所有支持的输出格式,可以包含图像,而不仅仅是LaTeX / PDF。

So something along these lines is planned to be a major new feature for the next major release of Pandoc, and will start to be working better in ODT/DOCX output as well. 因此,计划成为Pandoc下一个主要版本的主要新功能,并且将开始在ODT / DOCX输出中更好地工作。

Control over table/cell widths and line breaks within cells 控制单元格中的表格/单元格宽度和换行符

How exactly do you specify your tables in Markdown syntax? 您如何在Markdown语法中指定表格?

Are you aware that Pandoc supports several variations like gid_tables , pipe_tables , simple_tables and multiline_tables ? 您是否知道Pandoc支持多种变体,如gid_tablespipe_tablessimple_tablesmultiline_tables

You should look into using pandoc --from=markdown+multiline_tables ... as your command and write the critical tables as multiline_tables in your Markdown. 您应该考虑使用pandoc --from=markdown+multiline_tables ...作为您的命令,并将关键表格作为Markdown中的multiline_tables写入。

Read all about the details via man pandoc_markdown ... 通过man pandoc_markdown阅读所有关于细节的信息......

Multiline tables give you a limited control over the width of individual columns in the output, just by widening or narrowing the column widths in the markdown source itself. 多行表使您可以有限地控制输出中各列的宽度,只需通过加宽或缩小降价源本身的列宽即可。

Order of figures and tables when outputting LaTeX/PDF 输出LaTeX / PDF时的图表顺序

Pandoc supports the insertion of raw_tex lines and environments into the Markdown source file. Pandoc支持将raw_tex行和环境插入Markdown源文件。 When it encounters such lines, it transmits them un-changed into its LaTeX output. 当遇到这样的行时,它会将它们未更改地传输到其LaTeX输出中。 (But it will be ignored for all other outputs.) (但是对于所有其他输出,它将被忽略。)

So you can insert lines like 所以你可以插入像这样的行

\newpage{}

into the Markdown to enforce a page break. 进入Markdown以强制执行分页符。 This already gives you some limited control over keeping the order of mis-behaving figures or tables. 这已经为您提供了一些有限的控制,可以保持错误的数字或表格的顺序。 (After all, you said you look for a "quick and dirty" method, not a sophisticated typeset document...) (毕竟,你说你寻找一个“快速而肮脏”的方法,而不是复杂的排版文档...)

Of course, if you know LaTeX more and better, you can also use stuff like /FloatBarrier inside your Markdown. 当然,如果你更了解LaTeX,你也可以在你的Markdown中使用像/FloatBarrier这样的东西。

Going down that road (mixing LaTeX code into Markdown) gives you a few disadvantages: 走这条路(将LaTeX代码混合到Markdown)会给你带来一些缺点:

  1. The Markdown will not look as pretty any more. Markdown不再那么漂亮了。
  2. The Markdown will not work fully with other output formats (should you need them). Markdown无法与其他输出格式完全兼容(如果需要)。

But the advantage still are: 但优势仍然是:

  1. You will be writing and modifying the document text much faster in Markdown than authoring it in LaTeX. 您将在Markdown中以比在LaTeX中创作文档文本更快的速度编写和修改文档文本。
  2. You have some additional control over the final look of your PDF: 您可以对PDF的最终外观进行一些额外的控制:
    • order of tables + figures 表格+数字的顺序
    • look + width of tables + figures (because, you can of course insert a complete LaTeX 'figure' or 'table' environment). 表格+表格宽度+数字(因为,你当然可以插入一个完整的LaTeX'数字'或'表'环境)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM