Centering the table generated by the kable function of the knitr package

I am using the function kable()of the knitr package to create a table of good quality books in a pdf document. The output looks like the one below, where the table is on the left. enter image description here

I want to place the table in the center as shown below. enter image description here

I would be grateful if anyone could give some advice. I know I can do this using xtable. Is there a way to do this directly with kable?

The complete reproducible knitr code (.Rnw file) is as follows:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

<<results='asis'>>=
library(knitr)
kable(head(women), format='latex', booktabs=TRUE)
@

\end{document}
+4
source share
1 answer

With kableExtrayou can set the alignment using:

kable(head(women), "latex", booktabs = T) %>%
  kable_styling(position = "center")

http://haozhu233.imtqy.com/kableExtra/awesome_table_in_pdf.pdf

+2

Source: https://habr.com/ru/post/1613555/


All Articles