1

I am trying to add 2-4 spaces in front of the text in a single cell in kable. I want to do this for multiple rows. I was unable to make this work using the "align" option because it is too extreme for my purposes.

Is there a way to do this?

  • Welcome to Stack Overflow! It will be easier for us to help if you provide a reproducible example. Also take a look at https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – mhovd Apr 18 '21 at 14:12
  • If it's always the same, then `paste0(" ", df$column)` will do that. If you want to pad them based on current length, then perhaps something like `paste0(strrep(" ", max(nchar(df$column)) - nchar(df$column)), df$column)` or similar. – r2evans Apr 18 '21 at 14:15
  • 1
    But `align=` is completely different. Since the font is likely not fixed-width, adding spaces will be imperfect at best, alignment is likely the better option. I suggest you [edit] your question and add more context, such as a starting point (some `data.frame`, please just a few relevant rows), the code you've attempted, and some method of communicating your expected output. Thanks! – r2evans Apr 18 '21 at 14:24
  • You could use `str_pad()` from the `stringr` package, as another option. – Kat Apr 19 '21 at 04:52

0 Answers0