12

Is it possible to left-align the table caption? I am annoyed by the APA6th rules but I have to left-align the table caption somehow.

Take for example this table:

library(knitr)
library(kableExtra) 

kable(mtcars[1:10, 1:6], format = "latex", caption = "I need this left-aligned.", booktabs = T) %>% 
      kable_styling(position = "left") %>%
      group_rows("Group 1", 4, 7) %>%
      group_rows("Group 2", 8, 10)

The caption will always be centered above the table, even if I left-align the table position with kable_styling(position = "left").

EDIT: See here for a temporary solution that worked at least for me.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Jaynes01
  • 521
  • 1
  • 5
  • 20

1 Answers1

1

You only need to add the Latex package caption in the YAML header section with singlelinecheck=false specified to have the caption of your title left-aligned. Here is a reproducible example:

---
output:
  pdf_document: default
header-includes:
   - \usepackage[singlelinecheck=false]{caption}
---
```{r, echo = FALSE, message = FALSE}
library(knitr)
library(dplyr)
library(kableExtra)
```

```{r, echo = FALSE, message = FALSE}
kable(mtcars[1:10, 1:6], format = "latex", caption = "I need this left-aligned.", booktabs = T) %>% 
  kable_styling(position = "left") %>%
  group_rows("Group 1", 4, 7) %>%
  group_rows("Group 2", 8, 10)
```

Output:

enter image description here

Quinten
  • 35,235
  • 5
  • 20
  • 53