Reputation: 2019
I am using kableExtra
to format some tables in an Rmarkdown document. When running the code below, without any position
argument to kable_styling
, the grouping row labels (the rows in the table where it says "Group 1" and "Group 2") and the footnotes remain left aligned in relation to the table. This is as I would like it.
```{r cars-table, results='asis'}
kable(mtcars[1:10, 1:2], format = "html", caption = "Group Rows",
col.names = c("MPG[note]", "CYL[note]")) %>%
kable_styling("striped", full_width = F) %>%
group_rows("Group 1", 4, 7) %>%
group_rows("Group 2", 8, 10) %>%
add_footnote(c("Some footnote", "Some other footnote"))
```
But when a position
argument is provided to kable_styling
, the grouping row labels and footnotes seem to take the opposite alignment, rather than remaining left aligned in relation to the table. I say the opposite alignment, as when I use position = "right"
, the grouping row labels and footnotes become left aligned.
The code below demonstrates the issue when using position = "left"
.
```{r cars-table, results='asis'}
kable(mtcars[1:10, 1:2], format = "html", caption = "Group Rows",
col.names = c("MPG[note]", "CYL[note]")) %>%
kable_styling("striped", full_width = F, position = "left") %>%
group_rows("Group 1", 4, 7) %>%
group_rows("Group 2", 8, 10) %>%
add_footnote(c("Some footnote", "Some other footnote"))
```
I only load two libraries to make this example and use the defaults when opening an .Rmd document in RStudio.
library(knitr)
library(kableExtra)
What can I do to make the grouping row labels and footnotes left aligned in relation to the table? Thanks.
Upvotes: 3
Views: 2397
Reputation: 7826
In kableExtra
0.3.0 or earlier, there was a bug in the position
section of kable_styling
. The corresponding CSS for left
positioning was mistakenly set as text-align:right
... Thank you, @meenaparam, for bringing it up!
Now this bug has been addressed in the current dev version and the CRAN version will be updated in a week.
Upvotes: 2