如何在Pandoc Markdown转换为Latex PDF时实现交替行颜色表格?

3
我希望在通过pandoc将Markdown文档转换为(xe)latex PDF输出时,能够得到一张表格,并使用交替行颜色 - 如下所示:https://tex.stackexchange.com/questions/518097/booktabs-but-with-enclosing-border-around-the-table建议使用xcolor并添加table选项来实现交替行颜色。因此,我正在尝试使用test.md文件:
---
title: "Testing"
author: Bob Alice
date: July 13, 2010
geometry: margin=2cm
documentclass: extarticle
fontsize: 12pt
header-includes: |
    \usepackage[table]{xcolor}
    \rowcolors{2}{white}{gray!25}
output: pdf_document
---

Here is a test of a table:

+----------+-------------------+-----------------+
| Box name | Another parameter |  The IP address |
+==========+===================+=================+
| Test 1   | random-string-01  |       10.0.0.20 |
| Test 2   | random-string-02  |       10.0.0.30 |
+----------+-------------------+-----------------+

如果我通过pandoc进行转换:
$ pandoc --version
pandoc.exe 2.10 ...

使用以下方法:

pandoc test.md --pdf-engine=xelatex -o test.pdf

...结果如下:

Error producing PDF.
! LaTeX Error: Option clash for package xcolor.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.60 \rowcolors

看起来在这个设置中,似乎加载了 xcolor ,与其他选项冲突,包括 [table] 选项。

是否有可能诱导 pandoc 在没有使用自定义模板的情况下,生成带有交替行颜色的所有Latex/PDF文档中的表格?


1
我知道这并不能回答你的问题,但这是一个很好的参考:https://tex.stackexchange.com/questions/83101/option-clash-for-package-xcolor - user1759789
感谢@user1759789提供的链接 - 那个链接中包含了问题的解决方案! - sdbbs
1个回答

6

感谢评论中 @user1759789 提供的链接,似乎只需要在LaTeX文档类选项table中添加即可。然后当xcolor被加载时,此选项会被传递;请注意,如果您保留\usepackage[table]{xcolor}行,则代码仍将生成此错误。因此,经过修改的Markdown如下:

---
title: "Testing"
author: Bob Alice
date: July 13, 2010
geometry: margin=2cm
classoption: table
documentclass: extarticle
urlcolor: blue
fontsize: 12pt
header-includes: |
    \rowcolors{2}{gray!10}{gray!25}
output: pdf_document
---

Here is a test of a table ( [buggy](https://stackoverflow.com/questions/62835496/) ):

+----------+-------------------+-----------------+
| Box name | Another parameter |  The IP address |
+==========+===================+=================+
| Test 1   | random-string-01  |       10.0.0.20 |
| Test 2   | random-string-02  |       10.0.0.30 |
+----------+-------------------+-----------------+

and another grid table:

+----------+-------------------+-----------------+
| Box name | Another parameter |  The IP address |
+==========+===================+================:+
| Test 1   | random-string-01  | 10.0.0.20       |
+----------+-------------------+-----------------+
| Test 2   | random-string-02  | 10.0.0.30       |
+----------+-------------------+-----------------+

and pipe table:


| Box name        | Another parameter       |  The IP address |
|-----------------|-------------------------|-----------------|
| Test 1          | random-string-01        |       10.0.0.20 |
| Test 2          | random-string-02        |       10.0.0.30 |

...输出结果是:

test.pdf


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接