R kable linebreak cutting off striped color
Asked Answered
B

0

6

Below is a code example. My issue is that the background color for the rows with the linebreak are being cut short. Any idea how to fix this? I tried limiting the column width and that did the trick, but with other unwanted side effects such as aligning all the cell values at the top of each cell and as this final table must be dynamic in width, I don't want to force a certain column width. Thank you for any help.

---
title: "For Stackoverflow"
output:
  pdf_document:
    latex_engine: xelatex
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
- \usepackage{fontspec}
---


```{r message=FALSE, warning=FALSE}

library(dplyr)
library(kableExtra)

data <- data.frame(c('1','2','3','4','5'),c('a','b','A long line with no break that makes the column long','Value that needs \n break'
                                    , 'another value that needs \n break'))
names(data) <- c('Column 1', 'Column 2')

data <- data %>% mutate_all(linebreak)
#subbing center alignment
data$`Column 2` <- gsub('[l]','[c]',data$`Column 2`, fixed = TRUE)

kable(data, 'latex', booktabs = T, linesep="", escape=F, align=c('l','c')) %>%
    kable_styling(position = 'left', latex_options = c('striped','scale_down'), font_size = 12)


```

Picture of the result

Bite answered 5/2, 2020 at 20:23 Comment(1)
Response from package developer (not a solution): github.com/haozhu233/kableExtra/issues/452Micromho

© 2022 - 2024 — McMap. All rights reserved.