0
    ---
title: "Title"
author: ''
date: ''
output:
 pdf_document:
  template: default.tex
geometry: top=0.5cm, bottom=0.5cm, left=0.5cm, right=0.5cm
header-includes: null
fontsize: 4pt
classoption: portrait
sansfont: Calibri Light
---
#Name1: `r "Name1"`  
#Name2: `r "Name2"`

```{r,  echo=FALSE,  message=FALSE, warning=FALSE, results='asis'}
df <- mtcars
n = nrow(df)
hlines=c(-1,0,(n-1),n)
my_align = "c|c|c|ccccc|ccc|c|"
rws <- seq(1, (n-1), by = 2)
col <- rep("\\rowcolor[gray]{.90} ", length(rws))
xtable::print.xtable(xtable(df
, align = my_align)
, add.to.row = list(pos = as.list(rws), command = col)
, booktabs = F
, hline.after = hlines, type = "latex") 
```

I am using an Rmarkdown to print a table which has a lot of formatting. When I add the add.to.rwo part to get grey and white alternate rows the vertical lines are removed in the grey rows.

How do I correct this? It is very difficult to create a reproducible example but hopefully the same problem will apply to any df (with the correct Latex packages behind it)

Thanks :)

Anon.user111
  • 468
  • 1
  • 5
  • 16
  • Can't reproduce this. When I use your code with `df <- mtcars`, I get the proper formatted table... – Martin Schmelzer Jul 18 '16 at 19:00
  • I have figured out what the issue is but have no idea how to fix it. When I zoom in and zoom out various lines (including the hlines for the mtcars set) appear and disappear. If you zoom in and out on your pdf does the same thing occur? – Anon.user111 Jul 21 '16 at 12:24
  • No, can't reporoduce this either. I am using OSX, RStudio 0.99.902 and the RStudio Viewer to check the pdf. – Martin Schmelzer Jul 21 '16 at 12:32
  • Maybe this helps or leads to something helpful: http://tex.stackexchange.com/questions/176352/is-there-a-way-to-fix-the-rendering-of-tables-with-colored-cells or this http://tex.stackexchange.com/questions/170455/latex-table-rules-disappear-when-using-adobe-reader – Martin Schmelzer Jul 21 '16 at 12:35

1 Answers1

1

Try comparing these two tables. The first is your table as you coded it, the second is done by pixiedust with the hhline option set to TRUE.

---
title: "Title"
author: ''
date: ''
output:
 pdf_document:
geometry: top=0.5cm, bottom=0.5cm, left=0.5cm, right=0.5cm
header-includes: 
- \usepackage{amssymb} 
- \usepackage{arydshln} 
- \usepackage{caption} 
- \usepackage{graphicx} 
- \usepackage{hhline} 
- \usepackage{longtable} 
- \usepackage{multirow} 
- \usepackage[dvipsnames,table]{xcolor} 
fontsize: 4pt
classoption: portrait
sansfont: Calibri Light
---
#Name1: `r "Name1"`  
#Name2: `r "Name2"`

```{r,  echo=FALSE,  message=FALSE, warning=FALSE, results='asis'}
library(xtable)
df <- mtcars
n = nrow(df)
hlines=c(-1,0,(n-1),n)
my_align = "c|c|c|ccccc|ccc|c|"
rws <- seq(1, (n-1), by = 2)
col <- rep("\\rowcolor[gray]{.90} ", length(rws))
xtable::print.xtable(xtable(df
, align = my_align)
, add.to.row = list(pos = as.list(rws), command = col)
, booktabs = F
, hline.after = hlines, type = "latex") 
```

```{r}
library(pixiedust)
dust(df,
     hhline = TRUE,
     keep_rownames = TRUE) %>%
  medley_bw() %>%
  sprinkle_colnames(.rownames = "") %>%
  sprinkle(cols = c(".rownames", "mpg", "cyl", "qsec", "gear", "carb"),
           border = "right") %>%
  sprinkle(rows = nrow(mtcars),
           border = "top") %>%
  sprinkle(bg_pattern_by = "rows")
```
Benjamin
  • 16,897
  • 6
  • 45
  • 65