rr-markdownflextable

retain white spaces in flextable


How can I retain the (additional) white space of a character column in a flextable? The code sequence

flextable(data.frame("temp" = c("Lore ips", 
                                "dol  sit")))

generates the following image:

enter image description here

Note how the "ips" and "sit" subtexts would be aligned in the data.frame but are not aligned in the flextable.


Solution

  • White spaces are indeed collapsed in HTML output. You can use a tab instead:

    flextable(data.frame("temp" = c("Lore ips", "dol\tsit")))
    

    enter image description here

    Or you can add extra css instruction (for the HTML output):

    set_flextable_defaults(extra_css = ".tabwid{white-space: break-spaces;}")
    flextable(data.frame("temp" = c("Lore ips", "dol   sit")))
    

    enter image description here