Tables created from latex () from the Hmisc package are horizontally aligned to the left, and not horizontally aligned in a pdf document

Using R-studio and Knitr to create pdf, I cannot get the tables in the horizontal direction. As you can see from the example below, it works fine using xtable (), but latex () columns are left aligned. Since I understand the Hmisc documentation, tables created from latex () should be horizontally centered automatically, but I have to do something wrong.

\documentclass{article} \begin{document} <<>>= library(Hmisc) library(tables) library(xtable) @ The tables are all left-aligned: <<results='asis'>>= latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) ) @ <<results='asis'>>= latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ),center="center" ) @ <<results='asis'>>= latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ),center="centering" ) @ I have tried to use the fig.align option, but it does not do it: <<results='asis',fig.align='center'>>= latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) ) @ with xtable it automatically centers: <<results='asis'>>= xtable(table(Puromycin$conc, Puromycin$state)) @ \end{document} 

R version 3.0.0 (2013-04-03)

Platform: x86_64-w64-mingw32 / x64 (64-bit)

+6
source share
1 answer

I don't have time to go through the code in latex.s package, but as long as I do, feel free to wrap your pieces in the environment. Not the cleanest solution, but it does its job.

 \begin{centering} <<results='asis'>>= latex(tabular((Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris )) @ \end{centering} 

This creates a centered table.

+5
source

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


All Articles