skan skan - 4 months ago 32
LaTeX Question

ztable R package, can't get zebra stripes

I was trying the new ztable package to get a simple zebra stripped table on a pdf (with latex using a Rnw file with Rstudio).

\documentclass{article}
\usepackage[showframe,paper=a4paper,margin=1in]{geometry}
\begin{document}
<<tryal, eval=TRUE, echo=FALSE ,results="asis">>=
library(ztable)
output <- matrix(1:4, ncol=2, dimnames = list(list("Row 1", "Row 2"), list("Column 1", "Column 2")))
ztable(output, type="latex", zebra=1)
@
\end{document}


and I get this error

undefined control sequence


If I remove 'results=asis' I can see the latex code.

## Welcome to package ztable ver 0.1.5
## \definecolor{peach-orange}{rgb}{1.0, 0.8, 0.6}
## \begin{table}[!hbtp]
## \begin{center}
## \begin{normalsize}
## \color{black}
## \begin{tabular}{rrr}
## \hline
## &Column 1&Column 2\\
## \hline
## \cellcolor{peach-orange}Row 1&\cellcolor{peach-orange} 1&\cellcolor{peach-orange} 3\\
## Row 2& 2& 4\\
## \hline
## \end{tabular}
## \end{normalsize}
## \end{center}
## \end{table}
## \color{black}


What is the problem?. How can I get it?

If I remove the zebra=1 option it works well.

## Welcome to package ztable ver 0.1.5
## \begin{table}[!hbtp]
## \begin{center}
## \begin{normalsize}
## \color{black}
## \begin{tabular}{rrr}
## \hline
## &Column 1&Column 2\\
## \hline
## Row 1& 1& 3\\
## Row 2& 2& 4\\
## \hline
## \end{tabular}
## \end{normalsize}
## \end{center}
## \end{table}
## \color{black}


Is it a bug o my fault or maybe I need to install something?
I have the latest TexLive installed.
I don't have a clue about these things but I've also tried including a \usepackage{tabularx} with no success.

Answer

This one was tricky for me as well. I stumbled upon the following solution.

Add color and colortbl to usepackage. See en.wikibooks.org/wiki/LaTeX/Colors. Based on your example, adding these might look like this. There are other options available though if you want to enhance the color experience.

\usepackage[showframe,paper=a4paper,margin=1in]{geometry}
\usepackage{color}
\usepackage{colortbl}
Comments