Search code examples
rr-markdownkable

kable whitespace when writing to docx


I can't quite figure out how to get some whitespace into the cells of a table when writing to word. I hate word but unfortunately, I have to use it.

This is essentially what I hoped would work:

---
title: "Untitled"
output: word_document
---

```{r setup, include=TRUE}
library('magrittr')
tibble::tibble(
  wowie = c('A', '   B', '\tC')
) %>% 
  knitr::kable(
    format = 'markdown',
    escape = TRUE
  )

```

But instead we just get all this whitespace removed. Any suggestions on how to indent specific cells a bit?

Thanks


Solution

  • Any suggestions on how to indent specific cells a bit?

      (non-breaking space),   (en space) and   (em space) are used in HTML and word processing to create multiple spaces and can be combined together.

    ```{r setup, include=TRUE}
    library('magrittr')
    tibble::tibble(
      wowie = c('A', 
                ' B',           # add one space
                ' C',           # add two spaces 
                ' D',           # add four spaces
                '    F')   # add more spaces (combined together)
    ) %>% 
      knitr::kable(
        format = 'markdown',
        escape = TRUE
      )
    
    ```
    

    Output:

    enter image description here