This vignette introduces how to format columns in flextable.
The example below shows that colformat_md()
function parses markdown texts in flextable.
data.frame(
x = c("**bold**", "*italic*"),
y = c("^superscript^", "~subscript~"),
z = c("*[**~ft~^Extra^**](https://ftextra.atusy.net/) is*", "*Cool*"),
stringsAsFactors = FALSE
) %>%
as_flextable() %>%
colformat_md()
Currently, bold, italic, superscript, subscript, and link are well supported. Note that other syntax may result in unexpected behaviors. The ftExtra package does not support multiple paragraphs or block elements other than the paragraph.
You can also insert images. As markdown is parsed by pandoc, width and/or height attributes can be specified. Specifying one of them changes the other while keeping the aspect ratio.
data.frame(
R = c("{width=.5} is the great language"),
stringsAsFactors = FALSE
) %>%
as_flextable() %>%
colformat_md() %>%
flextable::autofit()
R |
|
The R logo is distributed by The R Foundation with the CC-BY-SA 4.0 license.
By default, soft line breaks becomes spaces.
linebreak |
a b |
Pandoc’s markdown supports hard line breaks by adding a backslash or double spaces at the end of a line.
linebreak |
a |
It is also possible to make \n
as a hard line break by extending Pandoc’s Markdown.
data.frame(linebreak = c("a\nb"), stringsAsFactors = FALSE) %>%
as_flextable() %>%
colformat_md(.from = "markdown+hard_line_breaks")
linebreak |
a |