kableExtra
kableExtra copied to clipboard
Remove italics from header row after row_spec(x, italic = T)
Hi, Is it possible to italicize the contents of a column but keep regular fonts in the header rows? The example below illustrates what I'm describing. The problem typically occurs for me when italicizing a column of species names with the header "Species" which I wouldn't want italicized.
Calling row_spec(1, italic = F)
after col_spec(1 italic = T)
seemed intuitive but didn't work. Maybe I'm missing something in the documentation. The code used to generate the table is also below.
Thanks, Kevin
kable(imp.data,align = c("l","l","r","r","r","r","r"),escape = F,longtable = T,booktabs = T) %>% kable_styling(position = "center",latex_options = c("repeat_header")) %>% column_spec(1, italic = T) %>% row_spec(1, italic = F) %>% add_header_above(c(" " = 2, "Frequency" = 5))
Emm, @kstierhoff, due to the mechanism of this package, I guess it's not very likely this can be implemented. I guess you will have to do it in the hard way.
library(kableExtra)
dt <- mtcars[1:6, 1:6]
dt$measurement <- row.names(dt)
dt <- dt[c(7, 1:6)]
row.names(dt) <- NULL
kable(dt,"latex", align = c("l","l","r","r","r","r","r"),
# put normalfont around your column name ---------------------------
col.names = c("\\normalfont{Measurement}", "Units", "18", "38", "70", "120", "200"),
# --------------------------------------
escape = F, longtable = T, booktabs = T) %>%
kable_styling(position = "center",latex_options = c("repeat_header")) %>%
column_spec(1, italic = T) %>%
add_header_above(c(" " = 2, "Frequency" = 5))
Hmm, now I rethink about it. It might be possible by wrapping things up in multicolumn
. I will give it a try over the weekend. Thanks for the suggestion, Kevin!
Thanks for thinking about this! The solution you propose will work just fine for me (and is not THAT hard), but a more elegant solution would be cool, especially for more complex tables. I'm just glad there's a way to override the italics header, which I couldn't figure out on my own (since I don't know Latex very well).