'Table layouts for use with Pandoc

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.

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

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>

This is the result in PDF:

PDF result



Solution 1:[1]

Since pandoc version 2.10, its internal document AST can represent table col- and rowspans.

Support for various input and output formats has been added in subsequent releases (html and latex should work already) and more are in the works!

Old answer

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.

Solution 2:[2]

From https://github.com/jgm/pandoc/wiki/Pandoc-vs-Multimarkdown:
"Pandoc's pipe tables [...] do not have all of the features of MMD pipe tables (sections, colspan, rowspan, grouping)."

Therefore, maybe a workaround could be to handle (complex) tables in reStructuredText in seperate files and include them afterwards. This are just my 2ยข because I will likely have to face this task not until a few weeks. If you found a solution please post it! I'm very curious, greets!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 elf12