Is there a way to format a single cell in a table in rmarkdown? I am using kable to generate a table as follows:
library(knitr)
kable(data.frame(c('a','b','c'),c(1,2,3)))
I wish to bold "c" in the last row and also add a horizontal line at the end of the table. Any pointers?
This also works: the first argument is row number, so you can bold rows programmatically or columns using column_spec.
library(kableExtra)
library(tidyverse)
kable(data.frame(letter =c('a','b','c'),number =c(1,2,3)))%>%
kable_styling()%>%
row_spec(3,bold=T,hline_after = T)
Highlighting cells, rows or columns with pander
is pretty straightforward:
> df <- data.frame(c('a','b','c'),c(1,2,3))
> emphasize.strong.cells(which(df == 3, arr.ind = TRUE))
> pander(df)
-------------------------------
c..a....b....c.. c.1..2..3.
------------------ ------------
a 1
b 2
c **3**
-------------------------------
But adding horizontal line to the table is out of the scope of markdown table specifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With