Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Striped is disabled if the cell contains line breaks. #879

Open
ujtwr opened this issue Dec 18, 2024 · 0 comments
Open

Striped is disabled if the cell contains line breaks. #879

ujtwr opened this issue Dec 18, 2024 · 0 comments

Comments

@ujtwr
Copy link

ujtwr commented Dec 18, 2024

Describe the bug
Striping does not work if the cell contains line breaks

To Reproduce
Knit PDF with RMarkdown containing the following code chunks

Cell color in row 5 becomes invalid.

---
title: "Untitled"
output: pdf_document
---
```{r}
library(tidyverse)
library(kableExtra)

tibble(
  v1 = 1:9,
  v2 = c(
    "without line breaks", "without line breaks", "without line breaks",
    "with line\nbreaks", "with line\nbreaks", "with line\nbreaks",
    "without line breaks", "without line breaks", "without line breaks"
  )
) %>% 
  kbl(
    booktabs = TRUE,
    linesep = "",
  ) %>% 
  kable_styling(
    latex_options = c(
      "HOLD_position",
      "striped"
    )
  ) %>% 
  column_spec(1, width = "0.05\\\\textwidth") %>% 
  column_spec(2, width = "0.9\\\\textwidth")

```

image

The Latex code looks like this:

\begin{table}[H]
\centering
\begin{tabular}[t]{>{\raggedleft\arraybackslash}p{0.05\textwidth}>{\raggedright\arraybackslash}p{0.9\textwidth}}
\toprule
v1 & v2\\
\midrule
\cellcolor{gray!10}{1} & \cellcolor{gray!10}{without line \cellcolor{gray!10}{breaks}}\\
2 & without line breaks\\
\cellcolor{gray!10}{3} & \cellcolor{gray!10}{without line breaks}\\
4 & with line
breaks\\
5 & with line
breaks\\
6 & with line
breaks\\
\cellcolor{gray!10}{7} & \cellcolor{gray!10}{without line breaks}\\
8 & without line breaks\\
\cellcolor{gray!10}{9} & \cellcolor{gray!10}{without line breaks}\\
\bottomrule
\end{tabular}
\end{table}

\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant