https://stackoverflow.com/questions/28166168/how-to-change-fontface-bold-italics-for-a-cell-in-a-kable-table-in-rmarkdown

format_cells(dat, rows, cols, fonttype)

Arguments

dat

A data.frame.

rows

The rows you want to apply formatting to.

cols

The columns you want to apply formatting to.

fonttype

fonttype = c("italics", "bold", "strikethrough").

Examples

df <- data.frame(char = c('a','b','c'),
                 num = c(1,2,3))

format_cells(df, 1, 1, "italics")
#>   char num
#> 1  *a*   1
#> 2    b   2
#> 3    c   3
format_cells(df, 2, 2, "bold")
#>   char   num
#> 1    a     1
#> 2    b **2**
#> 3    c     3
format_cells(df, 3, 1:2, "strikethrough")
#>    char   num
#> 1     a     1
#> 2     b     2
#> 3 ~~c~~ ~~3~~

library(knitr)
library(kableExtra)
library(magrittr)
df %>%
  format_cells(1, 1, "italics") %>%
  format_cells(2, 2, "bold") %>%
  format_cells(3, 1:2, "strikethrough") %>%
  knitr::kable()
#> <table>
#>  <thead>
#>   <tr>
#>    <th style="text-align:left;"> char </th>
#>    <th style="text-align:left;"> num </th>
#>   </tr>
#>  </thead>
#> <tbody>
#>   <tr>
#>    <td style="text-align:left;"> *a* </td>
#>    <td style="text-align:left;"> 1 </td>
#>   </tr>
#>   <tr>
#>    <td style="text-align:left;"> b </td>
#>    <td style="text-align:left;"> **2** </td>
#>   </tr>
#>   <tr>
#>    <td style="text-align:left;"> ~~c~~ </td>
#>    <td style="text-align:left;"> ~~3~~ </td>
#>   </tr>
#> </tbody>
#> </table>