0
votes

I am trying to convert a document written in Markdown *.md to Word *.docx using pandoc, but am having trouble setting the widths of table columns. As I understand the pandoc documentation, it should be possible to use the pipe_tables extension and --columns flag to specify relative column widths within which cell contents should wrap:

If a pipe table contains a row whose printable content is wider than the column width (see --columns), then the table will take up the full text width and the cell contents will wrap, with the relative cell widths determined by the number of dashes in the line separating the table header from the table body.

Consider this mcve.md:

||||
|-|-|---|
| 20% | this_column_should_take_up_20%_of_the_table_width | this column should take up 60% of the table's total width |

converted using the following command:

pandoc --from=markdown+pipe_tables --to=docx --columns=5 mcve.md -o mcve.docx

The resulting Word table has no wrapping of the middle column, with a narrow first column, and a narrow wrapped third column - not the expected relative widths or wrapping:

screenshot of converted Word table

By manually setting column widths in Word using the Layout -> AutoFit -> Fixed Column Width toolbar, I can reproduce the desired behaviour - but I'm really looking to automate this using pandoc.

screenshot of manually modified Word table

If converting from Markdown to PDF, this issue on GitHub explains how something similar to the desired output can be achieved.

Am I understanding the documentation wrong, or is there a way to do something similar when converting to *.docx format?

For info, this is the --version output for my pandoc command:

pandoc 1.19.2.4
Compiled with pandoc-types 1.17.0.5, texmath 0.9.4.4, skylighting 0.3.3.1

and I'm using MS Word for Office 365 MSO (16.0.11328.20362)

1

1 Answers

0
votes

The key from the documentation is:

the relative cell widths determined by the number of dashes in the line

So your table is formatted corrrectly, maybe a bit more human-readable version:

|            |            |                                    |
|------------|------------|------------------------------------|
| 20%        | this_column_should_take_up_20%_of_the_table_width | this column should take up 60% of the table's total width |

But you should try to update to the newest pandoc version.