As far as I know, pipe table syntax does not support line breaks in cells, therefore, if you use pandoc to convert markdowns to HTML (this is what RStudio uses), then you better choose another table syntax with a lot of functions, for example multiline or grid . You do not know how to do this with kable , but pander supports the following:
> library(pander) > colnames(s) <- c("Try Newline\nn","Try HTML break<br>%","Past 6 months\nn","\n%") > pander(s, keep.line.breaks = TRUE) ------------------------------------------------------- Try Newline Try HTML break<br>% Past 6 months % nn ------------- --------------------- --------------- --- 1 2 3 4 1 2 3 4 1 2 3 4 -------------------------------------------------------
But this is not enough, since line breaks are automatically deleted using pandoc , so you have to set hard line breaks ("backslash followed by a new line"), based on related documents . For instance. The following code will convert to HTML as expected:
> colnames(s) <- c("Try Newline\\\nn","Try HTML break\\\n%","Past 6 months\\\nn","\\\n%") > pander(s, keep.line.breaks = TRUE) ----------------------------------------------------- Try Newline\ Try HTML break\ Past 6 months\ \ n % n % -------------- ----------------- ---------------- --- 1 2 3 4 1 2 3 4 1 2 3 4 -----------------------------------------------------
source share