Xtable 灰色行覆盖垂直线

Xtable grey rows overwritting vertical lines

    ---
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") 
```

我正在使用 Rmarkdown 打印一个 table,其中有很多格式。当我添加 add.to.rwo 部分以获得灰色和白色交替行时,灰色行中的垂直线被删除。

我该如何纠正这个问题?创建一个可重现的示例非常困难,但希望同样的问题将适用于任何 df(背后有正确的 Latex 包)

谢谢 :)

尝试比较这两个 table。第一个是您编码时的 table,第二个是 pixiedusthhline 选项设置为 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")
```