kableextra

kableExtra how to use cell_spec from a user defined range?

这一生的挚爱 提交于 2021-02-17 03:28:27
问题 First, the package kableExtra indeed produces awesome table. I just have an additional request : When running this example ( from the manual) iris[1:10, ] %>% select(-Species) %>% mutate_if(is.numeric, function(x) { cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9), font_size = spec_font_size(x)) }) %>% kable("latex", escape = F, booktabs = T, linesep = "", align = "c") The cells are formated in each column. (1) How to adjust them to the entire table ? (2) Or to a user defined

kable, collapse_rows and booktabs: no alignement to the top

匆匆过客 提交于 2021-02-11 17:01:26
问题 I am trying to print a data.frame in a pdf using kable and collapse_rows functions. And it did not manage to make it works. Please try the following reprex: --- title: "Example" output: bookdown::pdf_document2 --- ```{r bandIdentif, echo=F} library(dplyr);library(kableExtra) dt <- data.frame(A = c(rep("a", 2), rep("b", 3)), B = c(paste("answer", 1:5))) kable(dt, "latex") %>% collapse_rows(columns = 1, valign = "top") ``` I have updated all the packages (MaxTex and R) and Rstudio. However, the

kableExtra : How can i set to bold the biggest value of the row?

↘锁芯ラ 提交于 2021-02-11 15:17:52
问题 Suppose i have a table that looks like : x = matrix(runif(10*5),nrow=10,ncol=5) When i display the matrix using kableextra , i want the highest value, per row, of say the last 2 rows, to be bolded. I looked at this document https://rdrr.io/cran/kableExtra/f/inst/doc/awesome_table_in_pdf.pdf a lot and i did not found how to use cell_spec correctly to perform this goal. 回答1: I thought this would be easier than it turned out to be. As far as I can see, this is how to do it: --- title: "Untitled"

Change background colour of knitr::kable headers

北战南征 提交于 2021-02-08 06:13:35
问题 I need to change the background colour of the headers of a table printed with knitr::kable. I can use kableExtra::column_spec to change the background of a whole column, but it doesn't affect the header row: library(knitr) library(kableExtra) kable(data.frame(a = 1, b = 2)) %>% column_spec(1, background = "yellow") Wanted outcome: A kable output where the header of column a has a yellow background (and the rest of the table a white background). 回答1: You can do this using cell_spec . For

Compact table in html document rmarkdown with kableExtra?

偶尔善良 提交于 2021-01-29 20:17:22
问题 I'm trying to make a 'compact' table in an RMarkdown I've tried a few things, mostly variations on setting a custom css class and providing the custom css class to a code chunk I've tried a lot of variations, all of which I can see flow through to the source code (accessed via knitting the html document, opening in chrome, and cmd + opt + u to view source and inspecting the source) However, I can't work out what's necessary to simply make rows thinner (I believe that's simply reducing cell

Using a for loop with knitr::kable and kableExtra::add_header_above

…衆ロ難τιáo~ 提交于 2021-01-29 14:18:38
问题 I am using R version 3.5.2 . I would like to evaluate a string in a kable function , but I am having some issues. Normally, I can pass a string through a for loop using the get function but in the kableExtra::add_header_above function I get the following error: Error: unexpected '=' in:"print(kable(df4,"html", col.names = c("zero","one")) %>% add_header_above(c(get("string") =" I have tried a handful of techniques like creating a string outside of the kable function and calling it, using page

html kable_styling not showing output in a for loop

℡╲_俬逩灬. 提交于 2021-01-29 08:15:07
问题 I want to use kable inside a for loop to generate a lot of tables in a HTML rmarkdown. I was looking for solutions and most of them are solved using the wrapper print around kable code. But when I want to generate html table outputs with kable_styling, this solution didn't work! For example: table <- tibble(a = c(1:10), b = letters[1:10]) for(each in 1:2) { print(table %>% kable()) cat("<br>") } This generate two simple tables. But when I try: table <- tibble(a = c(1:10), b = letters[1:10])

Renaming table's column name with Greek letters in kable

只谈情不闲聊 提交于 2021-01-28 21:30:40
问题 I am creating presentation using R Markdown with PDF (Beamer) as output. I am using library kableExtra for some formatting. The following code gives me the expected result library(knitr) # library(kableExtra) # create data frame df <- data.frame(mean = c(1,2,3), beta = c(5,6,7)) # print data frame to slide knitr::kable(df, col.names = c("mean", "$\\beta_t$")) However, when I use library(kableExtra) as in code below, the printed PDF show $\beta_t$ instead of the Greek letter beta. library

Changing the font size of headers of kableExtra table

廉价感情. 提交于 2021-01-27 13:21:53
问题 I am trying to change the font size of various headers in the following table. library(knitr) library(kableExtra) dt <- mtcars[1:5, 1:6] kable(dt) %>% kable_styling(c("striped", "bordered")) %>% add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>% add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>% add_header_above(c(" ", "Group 6" = 6)) Image of the table from the code above: However, I would like the header group 6 to be far bigger than Group 4 and 5 and groups 1

kableExtra: short.caption argument does not work if several dataframes are included in one table

孤者浪人 提交于 2021-01-27 07:43:32
问题 I have recently noticed that kable() from the kableExtra-package behaves oddly if more than one dataframe is included in the command. Short.caption argument is not used In this example, I create two data-frames and want to include them into one table. library(kableExtra) t1 <- c(68, 48, 50, 113, 98, 94) t2 <- c(26, 16, 22, 30, 16, 12) Group <- c("b1", "b2", "b3", "b4", "b5", "b6") cows <- data.frame(Group, t1, t2) colnames(cows) <- c("Group", "t1", "t2") kable(list(cows[1:3,], cows[4:6,]),