How to make row names bold in kableExtra table R Markdown

Hello,

I'm creating an R Markdown file and need to create a table using the kableExtra package. I want to make the rownames (A-H) bold. Having trouble finding the syntax to do that. I found a function called row_spec() but that applies a function to the whole row. Anybody have any ideas?

Here is my code for the table:

kbl(new) %>%
  kable_styling(bootstrap_options = "bordered")

And here is the data to create the table:

new <- structure(list(`1` = c("Std 0", "Std 0", "Std 1", "Std 1", "Std 2", 
"Std 2", "Std 3", "Std 3"), `2` = c("Std 4", "Std 4", "Std 5", 
"Std 5", "Cntrl", "Cntrl", "LRB", "LRB"), `3` = c("SMP 01", "SMP 01", 
"SMP 02", "SMP 02", "SMP 03", "SMP 03", "SMP 04", "SMP 04"), 
    `4` = c("SMP 05", "SMP 05", "SMP 06", "SMP 06", "SMP 07", 
    "SMP 07", "SMP 08", "SMP 08"), `5` = c("SMP 09", "SMP 09", 
    "SMP 10", "SMP 10", "SMP 11", "SMP 11", "SMP 12", "SMP 12"
    ), `6` = c("SMP 13", "SMP 13", "SMP 14", "SMP 14", "SMP 15", 
    "SMP 15", "SMP 16", "SMP 16"), `7` = c("SMP 17", "SMP 17", 
    "SMP 18", "SMP 18", "SMP 19", "SMP 19", "SMP 20", "SMP 20"
    ), `8` = c("SMP 21", "SMP 21", "SMP 22", "SMP 22", "SMP 23", 
    "SMP 23", "SMP 24", "SMP 24"), `9` = c("SMP 25", "SMP 25", 
    "SMP 26", "SMP 26", "SMP 27", "SMP 27", "SMP 28", "SMP 28"
    ), `10` = c("SMP 29", "SMP 29", "SMP 30", "SMP 30", "SMP 31", 
    "SMP 31", "SMP 32", "SMP 32"), `11` = c("SMP 33", "SMP 33", 
    "SMP 34", "SMP 34", "SMP 35", "SMP 35", "SMP 36", "SMP 36"
    ), `12` = c("SMP 37", "SMP 37", "SMP 38", "SMP 38", "SMP 39", 
    "SMP 39", "SMP 40", "SMP 40")), class = "data.frame", row.names = c("A", 
"B", "C", "D", "E", "F", "G", "H"))

Thanks so much!

You can use kableExtra::column_spec(1, bold = TRUE) after your code in the pipe to change the first column to bold (which are actually the values in the first column, even if they are row names).

Kind regards

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.