Kristof Kristof - 1 month ago 10
LaTeX Question

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

<table border="1">

<!-- First row -->

<td colspan="2">2 and 3</td>

<!-- Second row -->

<td rowspan="3">5, 9 and 13</td>

<!-- Third row -->


<!-- Fourth row -->

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


This is the result in PDF:

PDF result


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

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.