将Markdown管道表转换为Word / docx时换行错误

时间:2019-08-01 08:24:46

标签: markdown docx pandoc

我正在尝试使用pandoc将用Markdown *.md编写的文档转换为Word *.docx,但是在设置表列的宽度时遇到了麻烦。据我了解pandoc documentation,应该可以使用pipe_tables扩展名和--columns标志来指定单元格内容应在其中包裹的相对列宽:

  

如果管道表包含一行其可打印内容比列宽宽的行(请参见--columns),则该表将占据全文宽度,单元格内容将换行,相对单元格宽度由将表格标题和表格主体分隔开的行中的破折号。

考虑以下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 |

使用以下命令转换:

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

生成的Word表没有中间列的换行,第一列很窄,而第三列又很窄-而不是预期的相对宽度或换行:

screenshot of converted Word table

通过使用Layout -> AutoFit -> Fixed Column Width工具栏在Word中手动设置列宽,我可以重现所需的行为-但我确实希望使用pandoc来实现此自动化。

screenshot of manually modified Word table

如果从Markdown转换为PDF,this issue on GitHub解释了如何实现与所需输出相似的功能。

我是否理解文档错误,或者在转换为*.docx格式时是否可以做类似的事情?

有关信息,这是我的--version命令的pandoc输出:

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

我正在将MS Word用于Office 365 MSO(16.0.11328.20362)

1 个答案:

答案 0 :(得分:0)

文档中的键是:

  

由行中的破折号确定的相对像元宽度

因此,您的表格格式正确,可能是人类更易读的版本:

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

但是您应该尝试更新为newest pandoc version