Pandoc Markdown 到 Latex PDF:具有交替行颜色的表格?

sdb*_*bbs 3 pdf markdown latex pandoc

我想要一个表格,在 Markdown 文档的 (xe)latex PDF 输出中pandoc,具有交替的行颜色 - 如此处所述:

https://tex.stackexchange.com/questions/518097/booktabs-but-with-enending-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 |
+----------+-------------------+-----------------+
Run Code Online (Sandbox Code Playgroud)

如果我通过 pandoc 转换它:

$ pandoc --version
pandoc.exe 2.10 ...
Run Code Online (Sandbox Code Playgroud)

... 和:

pandoc test.md --pdf-engine=xelatex -o test.pdf
Run Code Online (Sandbox Code Playgroud)

...结果是:

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
Run Code Online (Sandbox Code Playgroud)

因此,显然xcolor是在这个设置中加载了与该[table]选项冲突的其他选项。

是否可以诱导pandoc在 Latex/PDF 文档中生成具有交替行颜色的所有表格 - 而不使用自定义模板?

sdb*_*bbs 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 |
Run Code Online (Sandbox Code Playgroud)

...输出是:

测试.pdf