I am having a dataframe with both character and numeric columns. I am trying to center the character column (which is done) and (I don't know how to) center flushed-right numeric column. Further, both column names are centered:
Some relevant posts (this and this), but I couldn't incorporate the techniques (if relevant) to my code.
The following code produces the table below:
df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))
kable(df, format="latex", align = c("c", "r")) %>%
kable_styling(full_width = TRUE) %>%
row_spec(0, align = "c")
I understand that I can use LaTeX code to produce a single user-customised table. But I need the example to be reproducible in Rmd (imagine I have lots of df
) and therefore need to specify within kable()
.
Should I modify the LaTeX table environment (i.e. \begin{tabu} to \linewidth {>{\centering}X>{\centering}X}
) and if so how in R, or use something like multirow
to customise the second column??