html_align | R Documentation |
Align text in columns of an htmlTable
at a
specific location (similar to align
or eqnarray
environments
in latex).
html_align(x, sep = " ", where = "&&", min_width = "35px")
x |
an object of class |
sep |
a character string used as the center of alignment |
where |
a character string or regular expression (see examples)
defining where strings should be aligned; the easiest method is to use
|
min_width |
minimum width of the span tag; too narrow will not align strings but too wide adds whitespace |
tmp <- within(cars, {
align2 <- sprintf('%s&&(%s)', speed, dist)
align1 <- sprintf('%s (%s)', speed, dist)
raw <- sprintf('%s - (%s)', speed, dist)
})
ht <- htmlTable::htmlTable(
head(tmp), n.cgroup = 2:3, cgroup = c('raw', 'align'),
caption = 'caption', rnames = FALSE
)
## default
structure(ht, class = 'htmlTable')
## align at '&&'
structure(html_align(ht), class = 'htmlTable')
structure(html_align(ht, ' --- '), class = 'htmlTable')
## align at '&&' or ' '
## the regex should capture the left text in group 1, use non-capture
## for separating text, andn capture the right text in group 2
structure(
html_align(ht, ' ', '(\\d+)(?: |&&)([()0-9]+)'),
class = 'htmlTable'
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.