I am trying to create a table using kable/kableextra without showing the horizontal lines in the table except for the first row which is the row names.
```
{r echo=FALSE}
library(knitr)
library(kableExtra)
options(knitr.kable.NA = '')
dt <- mtcars[1:5, 1:6]
kable(dt, "html") %>%
kable_styling(full_width = F, position = "left") %>%
row_spec(0, align = "c",bold=T ) %>%
column_spec(1, bold = T)
```
In the code above there is a line below the first row, which I like since those are row names, but there are lines between every row which I would like to remove.
Ideally I would like to have a slightly thicker line at the top at bottom of this table. Similar to the booktabs look in LaTeX.
I have read the documentation but the CSS is beyond me.
Thanks for any suggestions.
You can include a LaTeX table in your html doc as an image, but you need a complete LaTeX distribution (not tinytex) and the R package magick (+Ghostscript if you are on Windows).
Replace
kable(dt, "html") %>%
with
kable(dt, "latex", booktabs=T) %>%
and add
kable_as_image()
as last line (dont forget the pipe symbol). The following code works for me:
```{r echo=FALSE}
library(knitr)
library(kableExtra)
options(knitr.kable.NA = '')
dt <- mtcars[1:5, 1:6]
kable(dt, "latex", booktabs=T) %>%
kable_styling(full_width = F, position = "left") %>%
row_spec(0, align = "c",bold=T ) %>%
column_spec(1, bold = T) %>%
kable_as_image()
```
Ref: See page 24 here:
https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_pdf.pdf
What you need is to set booktabs = T
argument inside kable
.
In your example, just change the following line of code:
kable(dt, "html")
to:
kable(dt, "html", booktabs = T)
Cheers!
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