set_table_properties | R Documentation |
Set table layout and table width. Default to fixed algorithm.
If layout is fixed, column widths will be used to display the table;
width
is ignored.
If layout is autofit, column widths will not be used; table width is used (as a percentage).
set_table_properties(
x,
layout = "fixed",
width = 0,
align = NULL,
opts_html = list(),
opts_word = list(),
opts_pdf = list(),
word_title = NULL,
word_description = NULL
)
x |
flextable object |
layout |
'autofit' or 'fixed' algorithm. Default to 'autofit'. |
width |
The parameter has a different effect depending on the output format. Users should consider it as a minimum width. In HTML, it is the minimum width of the space that the table should occupy. In Word, it is a preferred size and Word may decide not to strictly stick to it. It has no effect on PowerPoint and PDF output. Its default value is 0, as an effect, it only use necessary width to display all content. It is not used by the PDF output. |
align |
alignment in document (only Word, HTML and PDF), supported values are 'left', 'center' and 'right'. |
opts_html |
html options as a list. Supported elements are:
|
opts_word |
Word options as a list. Supported elements are:
|
opts_pdf |
PDF options as a list. Supported elements are:
|
word_title |
alternative text for Word table (used as title of the table) |
word_description |
alternative text for Word table (used as description of the table) |
PowerPoint output ignore 'autofit layout'.
Other flextable dimensions:
autofit()
,
dim.flextable()
,
dim_pretty()
,
fit_to_width()
,
flextable_dim()
,
height()
,
hrule()
,
ncol_keys()
,
nrow_part()
,
width()
library(flextable)
ft_1 <- flextable(head(cars))
ft_1 <- autofit(ft_1)
ft_2 <- set_table_properties(ft_1, width = .5, layout = "autofit")
ft_2
ft_3 <- set_table_properties(ft_1, width = 1, layout = "autofit")
# add scroll for HTML ----
set.seed(2)
dat <- lapply(1:14, function(x) rnorm(n = 20))
dat <- setNames(dat, paste0("colname", 1:14))
dat <- as.data.frame(dat)
ft_4 <- flextable(dat)
ft_4 <- colformat_double(ft_4)
ft_4 <- bg(ft_4, j = 1, bg = "#DDDDDD", part = "all")
ft_4 <- bg(ft_4, i = 1, bg = "#DDDDDD", part = "header")
ft_4 <- autofit(ft_4)
ft_4 <- set_table_properties(
x = ft_4,
opts_html = list(
scroll = list(
height = "500px",
freeze_first_column = TRUE
)
)
)
ft_4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.