mifek
mifek

Reputation: 71

Column aligning does not work when using kableExtra linebreak

Creating a latex table using kbl and linebreak results in a weird alignement of the text column.

library(dplyr)
library(kableExtra)

data.frame(
  text = c(
    "Some longer line",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2"
    )
) %>%
mutate_all(linebreak) %>% 
kbl(booktabs = T, escape = F, format = "latex")

result tabl

How do I get the column left-aligned as expected?

Upvotes: 1

Views: 328

Answers (1)

mifek
mifek

Reputation: 71

Setting the align parameter in linebreak solves the problem.

data.frame(
  text = c(
    "Some longer line",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2",
    "Line 1\nLine 2"
    )
) %>%
mutate_all(linebreak, align = 'l') %>% 
kbl(booktabs = T, escape = F, format = "latex")

Upvotes: 3

Related Questions