r - Print HTML or Word table in knitr so that whitespaces in strings are respected -


using knitr , rstudio, i'm trying print dataframe html or word, leading whitespaces in versicolor, push versicolor right.

#data library(knitr )  library(xtable)  df <- iris[c(1,51),c(5,1)] df$species  <- as.character(df$species) df$species[ df$species=="versicolor"]  <- "         versicolor" 

trying different combinations of kable()...

#table kable(  df) kable(  df, right = false,align = c("l", "l" ) ) kable(  df, right = false,align = c("r", "l" ) ) 

i this: enter image description here

...or this: enter image description here

but i'm trying this: enter image description here

if you're willing muck html:

df$species[ df$species=="versicolor"]  <-    "<code style='background:white'>         </code>versicolor"` want 

or

df$species[ df$species=="versicolor"]  <-    "<span style='padding-left:30px'>         versicolor</span>" 

will left-space-padding.

the latter might cleaner programmatically (inserting multiples of # in padding-left.


Comments