I would like to have a table, in the (xe)latex PDF output of a Markdown document via pandoc, with alternating row colors - as noted here:
https://tex.stackexchange.com/questions/518097/booktabs-but-with-enclosing-border-around-the-table
... and
xcolorwith thetableoption to add alternating row colors
So, I'm trying this 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 |
+----------+-------------------+-----------------+
If I convert this via pandoc:
$ pandoc --version
pandoc.exe 2.10 ...
... with:
pandoc test.md --pdf-engine=xelatex -o test.pdf
... the result is:
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
So, apparently xcolor gets loaded in this setup, with other options, that clash with the [table] option.
Is it possible to coax pandoc into producing all tables in a Latex/PDF document with alternating row colors - without using custom templates?
Thanks to the link by @user1759789 in comments, it seems that it is enough to pass the Latex document class option table, which then gets passed when to xcolor when is loaded; note that the code will still generate this error, if you leave the \usepackage[table]{xcolor} line. So the working Markdown is this:
---
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 |
... and the output is:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With