Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

row_spec() function from kableExtra does not create a horizontal line in html output

I would like to add a horizontal line under one of the rows in my kableextra table. The parameter hline_after for row_spec function is supposed to add the horizontal line under the row:

row_spec documentation

However, this does not happen, the parameter appears to have no effect at all.

Example code:

x <- knitr::kable(head(mtcars), "html")
kableExtra::row_spec(x, 2, hline_after = TRUE)

Output

Does anyone know why this happens and is there another way to add the horizontal line to the table (using the same packages).

Thank you

EDIT As Lyngbakr pointed out, the function works when output is set to LaTeX.

like image 774
tadej Avatar asked Dec 06 '18 16:12

tadej


People also ask

What does Kable do in R?

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.

What is Kable?

Kable is a 3PL Provider Who Helps E-Retailers, Subscription Box Companies, and Consumer Brands Succeed Wherever You Sell-Your Website, Amazon, or Online Marketplaces.


1 Answers

As Lyngbakr pointed out in the comments, the function does not use the parameter hline_after in case the output is set to html. The parameter is only useful for latex output, it is just not mentioned explicitly in the documentation.

source code

An alternative to using the hline_after parameter is using extra_css:

x <- knitr::kable(head(mtcars), "html")
kableExtra::row_spec(x, 2, extra_css = "border-bottom: 1px solid")

However, in more complicated tables this will mess with other row_spec and column_spec calls that you might be using.

like image 84
tadej Avatar answered Oct 08 '22 06:10

tadej