haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
688 stars 147 forks source link

`row_spec` does not remove `hline` when specifying `hline_after = F` #819

Closed twillis209 closed 7 months ago

twillis209 commented 7 months ago

Using kableExtra v1.4.0.2, I can't use row_spec to remove \hline elements from a table.

library(kableExtra)
data.frame(a = c('a', 'b', 'c'), b = 1:3) |>
kbl(format = 'latex') |> 
row_spec(1:3, hline_after = F) |>
  cat()
#> 
#> \begin{tabular}[t]{l|r}
#> \hline
#> a & b\\
#> \hline
#> a & 1\\
#> \hline
#> b & 2\\
#> \hline
#> c & 3\\
#> \hline
#> \end{tabular}

Created on 2024-02-10 with reprex v2.1.0

I suspect this may just be incorrect use on my part.

dmurdoch commented 7 months ago

Yes, hline_after = FALSE is the default. If you set it to TRUE it will add \hline, but setting it to FALSE just leaves the lines alone. One way to remove the unwanted \hline entries is to use the booktabs style, e.g.

 library(kableExtra)
data.frame(a = c('a', 'b', 'c'), b = 1:3) |>
kbl(format = 'latex', booktabs=TRUE) |> 
  cat()

If that removes too many lines, you can add them back with row_spec(..., hline_after=TRUE).