I'd like to have zebra striped table rows in the PDF output converted from Markdown using Pandoc. To create Latex tables Pandoc relies on the packages booktabs and longtable. Therefore I tried to redefine the longtable environment. Here's a MWE (Markdown file content):

  - \usepackage[table]{xcolor}
  - \definecolor{lightgray}{gray}{0.95}
  - \let\OldLongtable\longtable
  - \let\OldEndLongtable\endlongtable
  - \renewenvironment{longtable}{\rowcolors{1}{white}{lightgray}\OldLongtable}{\OldEndLongtable}

| Right | Left | Default | Center |
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |

  : Demonstration of pipe table syntax.

The problem now is that the row coloring is wider than the actual table:

enter image description here

How can I fix this?

I've stumbled upon some information concerning this issue. The author of a Pandoc Latex Template called Eisvogel states:

Unfortunately the colored cells extend beyond the edge of the table because pandoc uses @-expressions (@{}) like so:


Additionally he links to the Latex Wikibook section about @-expressions. But to the Latex novice I am this is all as clear as mud...

Edit 2:
As requested by Zarko here's the same as a complete Latex document (output from Pandoc's Markdown-to-Latex conversion):

\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\else % if luatex or xelatex
% use upquote if available, for straight quotes in verbatim environments
% use microtype if available
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
\PassOptionsToPackage{hyphens}{url} % url is loaded by hyperref
            pdfborder={0 0 0},
\urlstyle{same}  % don't use monospace font for urls
% Fix footnotes in tables (requires footnote package)
\IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{long table}}{}
}{% else
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
% Redefines (sub)paragraphs to behave more like sections

% set default figure placement to htbp




\caption{Demonstration of pipe table syntax.}\tabularnewline
Right & Left & Default & Center\tabularnewline
Right & Left & Default & Center\tabularnewline
12 & 12 & 12 & 12\tabularnewline
123 & 123 & 123 & 123\tabularnewline
1 & 1 & 1 & 1\tabularnewline

  • we can't help you if you not provide complete small document beginning with \documentclass{...} and ending with \end{document}, which will reproduce your problem. welcome to tex.se! – Zarko Sep 30 '17 at 22:53
  • @Zarko I've added Latex output from Pandoc, hope that helps :) – Salim B Sep 30 '17 at 23:46
  • a litle bit :-). see if replacing \begin{longtable}[]{@{}rllc@{}} with \begin{longtable}[]{@{} >{\columncolor{white}[0pt][\tabcolsep]r ll >{\columncolor{white}[0pt][\tabcolsep] c@{}} helps. for testing i temporary haven't time :-( – Zarko Nov 5 '17 at 15:43
  • @ Zarko Thanks for your answer! But it seems there's a } missing somewhere. What you've proposed throws the error: unexpected "{" expecting letter or lf new-line \end{longtable} ^ – Salim B Nov 5 '17 at 21:23
  • indeed, they are missing :-(. before columns type: \begin{longtable}[]{@{} >{\columncolor{white}[0pt][\tabcolsep]}r ll >{\columncolor{white}[0pt][\tabcolsep]} c@{}}. now should work – Zarko Nov 5 '17 at 21:26

like this:

enter image description here

i extract from yours code minimal working example, where i add code which should solve your problem:

\usepackage{booktabs, longtable}

\begin{longtable}{@{}   >{\columncolor{white}[0pt][\tabcolsep]}r % <---
                        >{\columncolor{white}[\tabcolsep][0pt]}c % <---
                  @{}   }
\caption{Demonstration of pipe table syntax.}\\
Right & Left & Default & Center             \\
Right   & Left  & Default   & Center        \\
12      & 12    & 12        & 12            \\
123     & 123   & 123       & 123           \\
1       & 1     & 1         & 1             \\

  • Thanks a lot, this looks promising! But am I right on the assumption that this solution is tailored to the first one of the zebra colors (white) I've specified? It would be awesome if a generic solution could be found that ideally could be incorporated into Pandoc (or it's default Latex template) :) – Salim B Nov 5 '17 at 23:49
  • i only demonstrate principle (on one row) how to solve problem of coloring tables when you in specification of columns use on beginning and on the end @{}. this you can simply extend coloring each second row as is enabled by xcolor package. i newer use pandoc, so i haven't any clue, if integration require something special. from your example i can conclude, that you only need to add code lines indicated by % <---. lets say, that problem with \rowcolor{...} is solved, and left integration this solution to \pandoc` left to new question (if it is not straightforward). – Zarko Nov 6 '17 at 0:05
  • I appreciate your effort very much, no doubt about that! And I just realized that your solution works with any combination of row colors, not only when the first one is white! But my problem is that your solution forces me to break my whole document creation process because I can't directly convert from Markdown to PDF but instead have to compile an intermediary Latex file which I have to adjust for every single zebra-striped table before I can finally convert it to PDF. So it's not a complete solution to my original question... – Salim B Nov 6 '17 at 0:38
  • 1
    if it can't be incorporated, than the simple solution is : not use @{} on beginning and end of column specification :-) – Zarko Nov 6 '17 at 0:47
  • 2
    @SalimB, @{} on beginning and on the end remove \tabcolsep distance of the cell content from start of the first column and end of the last column. – Zarko Nov 6 '17 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.