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

How to change the strip color on kableExtra #41

Closed
shanakap opened this issue Aug 17, 2017 · 6 comments
Closed

How to change the strip color on kableExtra #41

shanakap opened this issue Aug 17, 2017 · 6 comments

Comments

@shanakap
Copy link

The color of the strips are very lite on Kable on Pdf output. So is there a way to change the color on kable_styling(latex_options = "striped")?

@haozhu233
Copy link
Owner

Hi, @shanakap, I added a new option stripe_color to kable_styling. Now you can do things like:

kable_styling(kable(...), latex_options = "striped", stripe_color = "red")

Right it only take native LaTeX color codes and those hex HTML codes won't work.

If necessary, I can write a global option to make it easier to use, when I have time.

Also, my current feeling is that for I'd better keep this feature within the LaTeX domain because HTML users can easily change the default bootstrap color by putting a CSS section in their document (https://stackoverflow.com/questions/20825211/bootstrap-table-striped-how-do-i-change-the-stripe-background-colour). However, that will change the stripe color for all tables in the document and it's actually difficult to change the color for only one table. 🤔

@shanakap
Copy link
Author

Thank you so much for adding this option. I tried to use this by re-installing kableExtra and knitr but get the following error,

Error in pdfTable_styling(kable_input, latex_options = latex_options,  : 
  unused argument (stripe_color = "red")
Calls: <Anonymous> ... freduce -> <Anonymous> -> kable_styling -> pdfTable_styling
In addition: Warning messages:
1: package 'kableExtra' was built under R version 3.3.3 
2: package 'knitr' was built under R version 3.3.3 
Execution halted

@haozhu233
Copy link
Owner

@shanakap have you installed from github via devtools::install_github("haozhu233/kableExtra")?

@shanakap
Copy link
Author

Hi @haozhu233 i figured out the issue,
The following code works fine, kable(table, booktabs = T,format = "latex") %>% kable_styling(latex_options = "striped", stripe_color = "red")

but soon as you try to use more option on kable_styling it does not work. ex: kable(table, booktabs = T,format = "latex") %>% kable_styling(latex_options = "striped", stripe_color = "red",row.names = FALSE)

Error is; Error in pdfTable_styling(kable_input, latex_options = latex_options, : unused argument (row.names = FALSE) Calls: <Anonymous> ... freduce -> withVisible -> <Anonymous> -> kable_styling Execution halted

@haozhu233
Copy link
Owner

Hi, @shanakap, I think if you want to take off the row names, you should use row.names = FALSE in the kable function. ;)

@Tixierae
Copy link

Tixierae commented May 7, 2020

Thanks for the great feature! Just one comment about:

it only take native LaTeX color codes and those hex HTML codes won't work.

A quick workaround is to (1) convert the HEX color you're interested in to RGB. There are plenty of online tools to do that. Just make sure your final values are within [0,1] by dividing them by 255. (2) define a custom LaTeX color with:

\definecolor{my_color}{rgb}{0.95,0.98,1.00} % replace by your RGB values!

Then that color can be called in R with:

...  %>% kable_styling(stripe_color='my_color')

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

3 participants