kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

Column alignment switches between rows

Open dietrichson opened this issue 3 years ago • 3 comments

Describe the bug Column alignment different for each row when using multi-line text in columns. See the pdf for output: testing-and-debug.pdf

To Reproduce Think about using reprex to generate an example in R.

knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(kableExtra)
dt_lb <- data.frame(
  I = c(   "1\nStuff to do\n more stuff",
           "2\nStuff to do\n more stuff",
           "3\nStuff to do\n more stuff",
           "4\nStuff to do\n more stuff"),
  II =  c("1\nMore meetings\n and coffe-breaks",
          "2\nMore meetings\n and coffe-breaks",
          "3\nMore meetings\n and coffe-breaks",
          "4\nMore meetings\n and coffe-breaks"),
  III = c("1\nthis is \n more text",
          "2\nthis is \n more text",
          "3\nthis is \n more text",
          "4\nthis is \n more text")
)

dt_lb %>%
  mutate_all(linebreak) %>%
  kbl(
    format = "latex",
  ,booktabs = T, escape = F, 
  col.names = c("One","TWO","THREE")
  ).

dietrichson avatar Apr 09 '21 11:04 dietrichson

This happens because you didn't specify alignment in the linebreak call. Probably missing align in that call should default to "l" instead of cycling through all choices.

dmurdoch avatar Dec 09 '21 21:12 dmurdoch

This happens because you didn't specify alignment in the linebreak call.

Not quite sure what this means, should I add additional parameters in the line: mutate_all(linebreak) %>%

Or am I missing a step?

On Thu, Dec 9, 2021 at 6:20 PM dmurdoch @.***> wrote:

This happens because you didn't specify alignment in the linebreak call. Probably missing align in that call should default to "l" instead of cycling through all choices.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/haozhu233/kableExtra/issues/603#issuecomment-990267845, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ6UTPYCBFHQERM2QCTV2DUQEMRFANCNFSM42U2ZV6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

dietrichson avatar Dec 13 '21 00:12 dietrichson

I think you just add extra parameters, e.g. mutate_all(linebreak, align = "l") %>% ... .

dmurdoch avatar Dec 13 '21 10:12 dmurdoch

Fixed in #676

dmurdoch avatar Dec 03 '23 13:12 dmurdoch