knitr::opts_chunk$set(echo = TRUE) library(r2rtf) library(dplyr)
This vignette documents how to use rtf_text
and rtf_paragraph
to customize text and paragraph in details. All output tables are saved in the vignettes/rtf
folder and assembled in vignettes/r2rtf_examples.docx
document.
text <- paste(rep("Sample Text", 20), collapse = " ")
text <- rep(text, 5)
Paragraph alignment supports four types.
r2rtf:::justification() %>% subset(type %in% c("l", "c", "r", "j"))
This example display text in different alignment methods.
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text), justification = c("l", "c", "r", "j") ) r2rtf:::write_rtf_para(res, "rtf/para-justification.rtf")
knitr::include_graphics("pdf/para-justification.pdf")
First line, left, and right indent can be controlled. One can also use a negative number to have the text "outdent".
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text), indent_first = c(1000, 0, -1000), indent_left = c(500, -500), indent_right = 500 ) r2rtf:::write_rtf_para(res, "rtf/para-indent.rtf")
knitr::include_graphics("pdf/para-indent.pdf")
Different types of line space can be controlled.
r2rtf:::spacing()[, 1:2]
This example show different line spaces in paragraph.
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text), space = c(1, 2, 1.5) ) r2rtf:::write_rtf_para(res, "rtf/para-line-space.rtf")
knitr::include_graphics("pdf/para-line-space.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text), space_before = c(50, 180), space_after = c(180, 50) ) r2rtf:::write_rtf_para(res, "rtf/para-space.rtf")
knitr::include_graphics("pdf/para-space.pdf")
This example add page break before paragraphs.
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text)[1:2], new_page = TRUE ) r2rtf:::write_rtf_para(res, "rtf/para-page.rtf")
knitr::include_graphics("pdf/para-page.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text, font_size = 8:12 )) r2rtf:::write_rtf_para(res, "rtf/text-font-size-1.rtf")
knitr::include_graphics("pdf/text-font-size-1.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text, format = c("b", "i", "bi", "^", "_", "u", "s") )) r2rtf:::write_rtf_para(res, "rtf/text-format-1.rtf")
knitr::include_graphics("pdf/text-format-1.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text, font = 1:10 )) r2rtf:::write_rtf_para(res, "rtf/text-font-type.rtf")
knitr::include_graphics("pdf/text-font-type.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text, color = c("red", "gold", "black", "orange", "blue") )) r2rtf:::write_rtf_para(res, "rtf/text-color.rtf")
knitr::include_graphics("pdf/text-color.pdf")
res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text, color = "white", background_color = c("red", "gold", "black", "orange", "blue") )) r2rtf:::write_rtf_para(res, "rtf/text-background-color.rtf")
knitr::include_graphics("pdf/text-background-color.pdf")
This example call rtf_text
multiple times to combine a text.
res <- r2rtf:::rtf_paragraph(paste0( r2rtf:::rtf_text("3.5"), r2rtf:::rtf_text("\\dagger", format = "^"), r2rtf:::rtf_text("\\line red ", color = "red"), r2rtf:::rtf_text("highlight", background_color = "yellow") )) r2rtf:::write_rtf_para(res, "rtf/text-combine1.rtf")
knitr::include_graphics("pdf/text-combine1.pdf")
This example call rtf_text
one time to combine a text.
text <- c(3.5, "\\dagger", "\\line red ", "highlight") format <- c("", "^", "", "") color <- c("black", "black", "red", "black") background_color <- c("white", "white", "white", "yellow") res <- r2rtf:::rtf_paragraph( paste( r2rtf:::rtf_text(text, format = format, color = color, background_color = background_color ), collapse = "" ) ) r2rtf:::write_rtf_para(res, "rtf/text-combine2.rtf")
knitr::include_graphics("pdf/text-combine2.pdf")
This example provide an inline formatting options with superscript and subscript. It is important to note the location of {}
is before the special character.
text <- c("X{_1} = \\alpha{^2} + \\beta{^\\dagger}") res <- r2rtf:::rtf_paragraph(r2rtf:::rtf_text(text)) r2rtf:::write_rtf_para(res, "rtf/text-combine3.rtf")
knitr::include_graphics("pdf/text-combine3.pdf")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.