Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am a LATEX/R/Sweave newbie and am encountering an issue while creating a report. The issue is that as shown in the figure below the first heading in the second table is blacked out.

Blacked out tables

I am able to replicate the issue with the below code:

\documentclass[xcolor=table,professionalfonts,a4paper,11pt]{article}
\usepackage[margin=1.0in]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage[skip=12pt]{caption}
\usepackage{colortbl, xcolor}
\usepackage{helvet}
\usepackage[noae]{Sweave}

\begin{document}

<<echo=FALSE, results=tex>>=
# Data
tabulatedVal <- data.frame(
Statistics = c("Annualized Return (%)", "Standard Deviation (%)", "Skewness", "Kurtosis", "Sharpe Ratio", "Maximum Drawdown", "Percent of losing months", "Worst Monthly Return", "Worst Yearly Return"),
Value =c(0.09, 6.77, 0.11, 3.18, 1.34, 5.20, 31.84, -4.09, -0.33))

#Table 1   
createdXTable <- xtable(tabulatedVal, digits = 2)
rws <- seq(1, nrow(tabulatedVal), by=2)
col <- rep("\\rowcolor{blue!10}", length(rws))
print(createdXTable, booktabs=TRUE, add.to.row=list(pos=as.list(rws), command=col), include.rownames=FALSE, size="\\small")


# Table 2
createdXTable <- xtable(tabulatedVal, digits = 2)
rws <- seq(1, nrow(tabulatedVal), by=2)
print(createdXTable, booktabs=TRUE, add.to.row=list(pos=as.list(rws), command=col), include.rownames=FALSE, size="\\small")
@


\end{document}

The .tex file being generated is as follows:

\documentclass[xcolor=table,professionalfonts,a4paper,11pt]{article}
\usepackage[margin=1.0in]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage[skip=12pt]{caption}
\usepackage{colortbl, xcolor}
\usepackage{helvet}
\usepackage[noae]{Sweave}

\begin{document}

% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Mon Apr 14 20:29:43 2014
\begin{table}[ht]
\centering
{\small
\begin{tabular}{lr}
  \toprule
Statistics & Value \\ 
  \midrule
Annualized Return (\%) & 0.09 \\ 
   \rowcolor{blue!10}Standard Deviation (\%) & 6.77 \\ 
  Skewness & 0.11 \\ 
   \rowcolor{blue!10}Kurtosis & 3.18 \\ 
  Sharpe Ratio & 1.34 \\ 
   \rowcolor{blue!10}Maximum Drawdown & 5.20 \\ 
  Percent of losing months & 31.84 \\ 
   \rowcolor{blue!10}Worst Monthly Return & -4.09 \\ 
  Worst Yearly Return & -0.33 \\ 
   \rowcolor{blue!10} \bottomrule
\end{tabular}
}
\end{table}% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Mon Apr 14 20:29:43 2014
\begin{table}[ht]
\centering
{\small
\begin{tabular}{lr}
  \toprule
Statistics & Value \\ 
  \midrule
Annualized Return (\%) & 0.09 \\ 
   \rowcolor{blue!10}Standard Deviation (\%) & 6.77 \\ 
  Skewness & 0.11 \\ 
   \rowcolor{blue!10}Kurtosis & 3.18 \\ 
  Sharpe Ratio & 1.34 \\ 
   \rowcolor{blue!10}Maximum Drawdown & 5.20 \\ 
  Percent of losing months & 31.84 \\ 
   \rowcolor{blue!10}Worst Monthly Return & -4.09 \\ 
  Worst Yearly Return & -0.33 \\ 
   \rowcolor{blue!10} \bottomrule
\end{tabular}
}
\end{table}

\end{document}

Any help is appreciated. Thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The problem is that you have an extra

\rowcolor{blue!10} \bottomrule

at the bottom of your tables; this is somehow affecting what follows.

You're actually making one too many of the \\rowcolor{blue!10} in your rep command; it adds it on to the end of the line but affects the next line. To fix, just make rws have one less like this.

rws <- seq(1, nrow(tabulatedVal)-1, by=2)

Also, for future reference it is helpful to only include the packages that are necessary for recreating the issue. This can also help you figure out the issue (though wouldn't have here). In this case a smaller example would have been

\documentclass{article}
\usepackage{colortbl}
\begin{document}
<<echo=FALSE, results=tex>>=
library(xtable)
tabulatedVal <- data.frame(Statistics = c("Annualized Return (%)", "Standard Deviation (%)", 
                               "Skewness", "Kurtosis", "Sharpe Ratio", "Maximum Drawdown", 
                               "Percent of losing months", "Worst Monthly Return", "Worst Yearly Return"),
                           Value = c(0.09, 6.77, 0.11, 3.18, 1.34, 5.20, 31.84, -4.09, -0.33))
createdXTable <- xtable(tabulatedVal, digits = 2)
rws <- seq(1, nrow(tabulatedVal), by=2)
col <- rep("\\rowcolor{cyan}", length(rws))
print(createdXTable, add.to.row=list(pos=as.list(rws), command=col), include.rownames=FALSE)
print(createdXTable, add.to.row=list(pos=as.list(rws), command=col), include.rownames=FALSE)
@
\end{document}
share|improve this answer
    
Thanks, that fixed the issue. I added the extra packages as I was not sure if it was somehow interfering with the required packages and causing issues. –  john_zac Apr 14 at 15:56
    
Glad this helped. In response to your comment, that's exactly the issue. Removing the extra packages can help determine what the issue is. –  Aaron Apr 14 at 16:12
    
@john_zac Duplicate of stackoverflow.com/questions/18969749/… –  Yihui Apr 17 at 6:01

The problem occurs due to the \rowcolor{blue!10}\bottomrule at the bottom of the first table. As a workaround you can manually remove the last \rowcolor{} command but I'm afraid I don't know how to get that done automatically. I would have posted this as comment but don't have the rep.

\documentclass[xcolor=table,professionalfonts,a4paper,11pt]{article}
\usepackage[margin=1.0in]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage[skip=12pt]{caption}
\usepackage{colortbl, xcolor}
\usepackage{helvet}
\usepackage[noae]{Sweave}

\begin{document}

\begin{table}[ht]
\centering
{\small
\begin{tabular}{lr}
  \toprule
Statistics & Value \\ 
  \midrule
Annualized Return (\%) & 0.09 \\ 
   \rowcolor{blue!10}Standard Deviation (\%) & 6.77 \\ 
  Skewness & 0.11 \\ 
   \rowcolor{blue!10}Kurtosis & 3.18 \\ 
  Sharpe Ratio & 1.34 \\ 
   \rowcolor{blue!10}Maximum Drawdown & 5.20 \\ 
  Percent of losing months & 31.84 \\ 
   \rowcolor{blue!10}Worst Monthly Return & -4.09 \\ 
  Worst Yearly Return & -0.33 \\ 
   \bottomrule % This line was changed
\end{tabular}
}
\end{table}
\begin{table}[ht]
\centering
{\small
\begin{tabular}{lr}
  \toprule
Statistics & Value \\ 
  \midrule
Annualized Return (\%) & 0.09 \\ 
   \rowcolor{blue!10}Standard Deviation (\%) & 6.77 \\ 
  Skewness & 0.11 \\ 
   \rowcolor{blue!10}Kurtosis & 3.18 \\ 
  Sharpe Ratio & 1.34 \\ 
   \rowcolor{blue!10}Maximum Drawdown & 5.20 \\ 
  Percent of losing months & 31.84 \\ 
   \rowcolor{blue!10}Worst Monthly Return & -4.09 \\ 
  Worst Yearly Return & -0.33 \\ 
   \bottomrule % This line changed too for good measure
\end{tabular}
}
\end{table}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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