13

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.

tadej
  • 400
  • 1
  • 2
  • 11
  • It works for me in LaTeX. It doesn't, however, for html. Looking at the code, this isn't surprising since `hline_after` isn't even passed to `row_spec_html`, the internal function that actually creates the table in html. It is passed to `row_spec_latex`, though. – Dan Dec 06 '18 at 16:55
  • You are right, I had a separate issue with my latex output (I never use it otherwise). I checked the source code too now, the parameter is only for latex output, it just does not mention it in the documentation itself. I've edited the question. Thank you – tadej Dec 07 '18 at 08:40
  • If you're not set on `kable`/`kableExtra`, you could use [`xtable`](https://cran.r-project.org/web/packages/xtable/index.html). – Dan Dec 07 '18 at 12:01
  • Yes, true. For my current case I don't need it, extra_css was enough. The next time I need to use more advanced formatting, I will look into it. Thanks – tadej Dec 10 '18 at 08:25

1 Answers1

17

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.

tadej
  • 400
  • 1
  • 2
  • 11