我有一些 HTML 表格,当使用浏览器呈现时,这些表格看起来通常是换行的。但是当我尝试使用 转换为 pdf 时pdftex,表格在边缘处被切断并且没有换行。如何让 pandoc 包裹 HTML 表格?
和markdown问题不一样。表格是纯 html。
问题是,如果您希望单元格换行,LaTeX 需要明确指定列宽,因此您需要以某种方式手动指定这些宽度(在 markdown 中,您将使用多行或网格表来执行此操作)。
Pandoc 的 HTML Reader 支持元素width的相对属性col。
pandoc -f html -t latex << EOF
> <table>
> <colgroup>
> <col width="10%">
> <col width="90%">
> </colgroup>
> <tr>
> <td>3476896</td>
> <td>My first HTML</td>
> </tr>
> </table>
>
> EOF
\begin{longtable}[c]{@{}ll@{}}
\toprule
\begin{minipage}[t]{0.09\columnwidth}\raggedright\strut
3476896
\strut\end{minipage} &
\begin{minipage}[t]{0.85\columnwidth}\raggedright\strut
My first HTML
\strut\end{minipage}\tabularnewline
\bottomrule
\end{longtable}
Run Code Online (Sandbox Code Playgroud)
注意\columnwidthLaTeX 输出中的 。
如果您无法控制 HTML,您可以编写一个Pandoc 过滤器来修改文档的 AST 并设置一些任意列宽,总和为 100%。也许你还应该在 pandoc-discuss 上恢复这个旧线程,其中 jgm aka fiddlosopher 写道:
主要原因是,对于更复杂的表格,我们需要有关相对列宽的信息,而 HTML 文档缺乏这些信息。但我想我越来越相信我们应该猜测这些。
或者提交功能请求来请求此功能。