0

I am trying to get my kable table to align in the center of my pdf from RMarkdown. Currently, it is aligning very left of my page and the caption is awkwardly floating in the center (pic at bottom).

I have tried the following code and still no luck:

version 1:

{r, eval=TRUE, echo=FALSE, fig.align='center'}
library(knitr)
library(kableExtra)
knitr::kable(latent_label_results, caption="Latent Model Parameter Estimates", row.names = FALSE, digits=2, align='lcc', booktabs = T, longtable = T) %>% kable_styling()

version 2:

kable(latent_label_results, caption="Latent Model Parameter Estimates", 
      row.names = FALSE, digits=2, booktabs = T, longtable = T) %>%
  kable_styling(position="center")

It seems no matter what I do, I am left with this message,

In styling_latex_position_right(x, table_info, hold_position, table.envir) : Position = right is only supported for longtable in LaTeX. Setting back to center...

but it never centers. Any help would be greatly appreciated

enter image description here

3
  • By default kable center both the table and the caption, but you showed an incomplete and not compilable R chunk, that nonetheless completed with some faked data produce the expected centered result, so ....
    – Fran
    Jun 30, 2020 at 19:22
  • Maybe kable(latent_label_results, "latex", row.names = FALSE, digits=2, longtable = T, booktabs = T) %>% kable_styling(position="center")
    – Ross
    Jul 1, 2020 at 15:58
  • Thanks Ross for the suggestion, this hasn't worked either. I am going to try and find a workaround. If I find one, I will post it here
    – user219499
    Jul 2, 2020 at 19:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.