Learn R Programming

flextable (version 0.9.11)

font: Set font

Description

Change the font of selected rows and columns of a flextable.

Fonts impact the readability and aesthetics of the table. Font families refer to a set of typefaces that share common design features, such as 'Arial' and 'Open Sans'.

'Google Fonts' is a popular library of free web fonts that can be easily integrated into flextable with the gdtools::register_gfont() function. When the output is HTML, the font will be automatically added to the HTML document.

Usage

font(
  x,
  i = NULL,
  j = NULL,
  fontname,
  part = "body",
  cs.family = fontname,
  hansi.family = fontname,
  eastasia.family = fontname
)

Arguments

x

a 'flextable' object, see flextable-package to learn how to create 'flextable' object.

i

row selector, see section Row selection with the i parameter in <Selectors in flextable>.

j

column selector, see section Column selection with the j parameter in <Selectors in flextable>.

fontname

single character value, the font family name. With Word and PowerPoint output, this value specifies the font to be used for formatting characters in the Unicode range (U+0000-U+007F).

part

part selector, see section Part selection with the part parameter in <Selectors in flextable>. Value 'all' can be used.

cs.family

Optional font to be used for formatting characters in a complex script Unicode range. For example, Arabic text might be displayed using the "Arial Unicode MS" font. Used only with Word and PowerPoint outputs. The default value is the value of fontname.

hansi.family

Optional font to be used for formatting characters in a Unicode range that does not fall into one of the other categories. Used only with Word and PowerPoint outputs. The default value is the value of fontname.

eastasia.family

Optional font to be used for formatting characters in an East Asian Unicode range. For example, Japanese text might be displayed using the "MS Mincho" font. Used only with Word and PowerPoint outputs. The default value is the value of fontname.

See Also

Other sugar functions for table style: align(), bg(), bold(), color(), empty_blanks(), fontsize(), highlight(), italic(), keep_with_next(), line_spacing(), padding(), rotate(), style(), tab_settings(), valign()

Examples

Run this code
library(gdtools)
fontname <- "Brush Script MT"

if (font_family_exists(fontname)) {
  ft_1 <- flextable(head(iris))
  ft_2 <- font(ft_1, fontname = fontname, part = "header")
  ft_2 <- font(ft_2, fontname = fontname, j = 5)
  ft_2
}

Run the code above in your browser using DataLab