How can I make the header bold when using knitr::kable()
function? It is automatically formatted as bold in HTML or word output, however, I couldn't change the format of the header when pdf output is selected.
Sample Code:
library(knitr)
kable(head(iris))
Output:
Image - The table header in pdf is not bold.
10.1 The function knitr::kable() The kable() function in knitr is a very simple table generator, and is simple by design. It only generates tables for strictly rectangular data such as matrices and data frames. You cannot heavily format the table cells or merge cells.
The kableExtra package (Zhu 2021) is designed to extend the basic functionality of tables produced using knitr::kable() (see Section 10.1).
Use kableExtra
and format the table header with bold text.
library(knitr)
library(kableExtra)
kable(head(iris),format="latex") %>% row_spec(0,bold=TRUE) %>%
kable_styling()
...and the output:
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