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):
---
header-includes:
- \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:
How can I fix this?
Edit:
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:
\begin{longtable}[]{@{}ll@{}}
\end{longtable}
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):
\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\PassOptionsToPackage{hyphens}{url} % url is loaded by hyperref
\usepackage[unicode=true]{hyperref}
\hypersetup{
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\usepackage{longtable,booktabs}
% Fix footnotes in tables (requires footnote package)
\IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{long table}}{}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
% set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.95}
\let\OldLongtable\longtable
\let\OldEndLongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{1}{white}{lightgray}\OldLongtable}{\OldEndLongtable}
\date{}
\begin{document}
\begin{longtable}[]{@{}rllc@{}}
\caption{Demonstration of pipe table syntax.}\tabularnewline
\toprule
Right & Left & Default & Center\tabularnewline
\midrule
\endfirsthead
\toprule
Right & Left & Default & Center\tabularnewline
\midrule
\endhead
12 & 12 & 12 & 12\tabularnewline
123 & 123 & 123 & 123\tabularnewline
1 & 1 & 1 & 1\tabularnewline
\bottomrule
\end{longtable}
\end{document}
Best Answer
like this:
i extract from yours code minimal working example, where i add code which should solve your problem: