与Pandoc一起使用的表格布局 [英] Table layouts for use with Pandoc

查看:515
本文介绍了与Pandoc一起使用的表格布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建文档生成工作流程(专业文档).目标是尽可能在Markdown中编写.生成的文档应为PDF,但在必要时仍可以导出为.docx.

I'm trying to create a document generation workflow (professional documents). The goal is to write as much as possible in Markdown. The resulting document should be PDF, while still being able to export to .docx if necessary.

我选择了Pandoc,为此我将创建一个Latex模板并使用YAML文档来保存文档元数据.到目前为止,一切都很好.但是,我有时会需要使用表格,从非常简单的表格到更复杂的布局,例如列跨越.

I've settled on Pandoc, for which I'll create a Latex template and use a YAML document to hold the document metadata. So far so good. However, from time to time I need to use tables, ranging from very simple ones to more complex layouts with e.g. column spanning.

除了最简单的表外,Markdown几乎不能用于其他任何东西.我尝试使用HTML定义更复杂的表布局,但Pandoc似乎不知道如何处理列或行跨度.

Markdown is hardly usable for anything but the most simple tables. I tried HTML to define a more complex table layout, but it seems that Pandoc doesn't know how to handle column or row spanning.

如果没有其他替代方法可以轻松维护定义表的方法,同时仍然可以使用Pandoc将其转换为Latex/PDF,则可以在Latex中完全定义表吗?

Short of defining the table completely in Latex, if there any other alternative that allows an easy to maintain approach to defining tables while still being able to convert them with Pandoc to Latex/PDF?

一个更复杂的表的示例(摘自此处 ):

An example of a more complex table (taken from here):

<body>
<table border="1">

<!-- First row -->

<tr>
<td>1</td>
<td colspan="2">2 and 3</td>
<td>4</td>
</tr>

<!-- Second row -->

<tr>
<td rowspan="3">5, 9 and 13</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>

<!-- Third row -->

<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>

<!-- Fourth row -->

<tr>
<td colspan="3">14, 15 and 16</td>
</tr>

</table>
</body>

这是PDF的结果:

推荐答案

实际上是Pandoc, t (当前)支持col-或rowpans.

Indeed, Pandoc doesn't (currently) support col- or rowspans.

如果您绝对需要单元格跨度以用于多种输出格式,那么最好的选择是将表(在pandoc markdown的代码块或<div class="table">内)以所需的任何格式(例如HTML或什至 pandoc过滤器,将Pandoc AST的这一部分转换为HTML,然后编写另一个过滤器将其转换为LaTeX.

If you absolutely need cell-spans for multiple output formats, your best bet is to write your tables (inside pandoc markdown's codeblocks or a <div class="table">) in whatever format you desire (e.g. HTML or even reStructuredText). Then you can write one pandoc filter that converts this part of the pandoc AST to HTML, and another filter that converts it to LaTeX.

这篇关于与Pandoc一起使用的表格布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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