如何在 Pandoc 生成的 PDF 表格中添加垂直线

2024-02-22

有没有办法让 Pandoc 在 PDF 输出表格中放置垂直线,而无需编辑 Pandoc 的源代码?

目前我正在使用以下方法生成 PDF:

pandoc --template pandoc-template.tex -V geometry:margin=1in -V geometry:a4paper --number-sections --variable file1.md -o file1.pdf

该表的降价看起来像:

+-----------------+-----------------+
| Row 1           | Some data 1     |
| Row 2           | Some data 2     |
+-----------------+-----------------+

Pandoc 简单地忽略垂直线。我发现了有关该主题的多个问题,但答案仍然不明确。

为上面的降价生成的 Latex 可能看起来像这样,其中管道字符告诉 Latex 为表格生成垂直线:

\begin{longtable}{ | l | l |}
  \hline                       
  Row 1 & Some data 1 \\
  Row 2 & Some data 2 \\
  \hline  
\end{longtable}

下面的代码来自 LaTex.hs Pandoc 源文件。我不是 Haskell 开发人员,但它似乎没有选项来添加在 LaTex 中创建垂直线所需的管道字符。

  let colDescriptors = text $ concat $ map toColDescriptor aligns
  modify $ \s -> s{ stTable = True }
  return $ "\\begin{longtable}[c]" <>
              braces ("@{}" <> colDescriptors <> "@{}")
              -- the @{} removes extra space at beginning and end
         $$ "\\toprule\\addlinespace"
         $$ headers
         $$ vcat rows'
         $$ "\\bottomrule"
         $$ capt
         $$ "\\end{longtable}"

toColDescriptor :: Alignment -> String
toColDescriptor align =
  case align of
         AlignLeft    -> "l"
         AlignRight   -> "r"
         AlignCenter  -> "c"
         AlignDefault -> "l"

除了对 pandoc 的乳胶输出进行后处理之外,目前无法添加垂直线。根据这个https://github.com/jgm/pandoc/issues/922 https://github.com/jgm/pandoc/issues/922

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Pandoc 生成的 PDF 表格中添加垂直线 的相关文章

随机推荐