setWidths | R Documentation |
Properly setting column widths given the maximum width of the table, for non-html output only.
setWidths(x, header1, maxTableWidth = 7, rowHeaderInd = NULL,
minFontSize=9, nRowPerRowHeader=NULL)
breakRatio(aStr)
x |
A flextable object |
header1 |
(character vector) the first row of the column header |
maxTableWidth |
(numeric, 7.0) the maximum width of the table in inch. The default 7.0 corresponds to "PAGE LAYOUT" > "size" > "letter"; "Margins" > "Moderate" in MS Word. |
rowHeaderInd |
(integer, NULL) See |
minFontSize |
(integer, 9) The minimum font size in table body. |
nRowPerRowHeader |
(integer vector, NULL) The average number of rows spanned by each row header under a row header index. So it's a vector of length |
aStr |
(a character string) The string is the content of a header cell. |
setWidths
sets the width of each column of a table to fit maxTableWidth
. Here is a brief description of its algorithm:
let HBWidths = mapply(max, wHeader,wBody)
if(sum(HBWidths) <= maxTableWidth), set HBWidths to be the final table widths.
Else if(sum(HBWidths)/maxTableWidth < 1.08), reducing font size by 1, set HBWidths*0.92 to be the final table widths.
Else
For columns where the header is longer than the body and the header is a single word, wrap the header at a non-letter character closest to the middle of the header.
If the table still doesn't fit, further wrapping the columns of row headers if any, and if the cells under those columns span vertically across multiple cells.
If the table still doesn't fit, reduce font size up to minFontSize
If the table still doesn't fit, wrap the table body, staring from the longest table columns, until the table fits.
breakRatio
computes the wrapping point of a header.
(numeric) by breakRatio
, the ratio of the original length after wrapping.
(list) by setWidths
. The list contains 1)widths: a numeric vector of column widths and 2)fs: the new font size.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.