6

R-studio と Knitr を使用して pdf を作成すると、テーブルを水平方向に中央に配置できません。以下の例からわかるように、xtable() を使用すると問題なく動作しますが、latex() テーブルはすべて左揃えです。Hmisc のドキュメントを理解しているので、latex() から作成されたテーブルは水平方向に自動的に中央に配置されるはずですが、何か間違ったことをしているに違いありません。

\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 バージョン 3.0.0 (2013-04-03)

プラットフォーム: x86_64-w64-mingw32/x64 (64 ビット)

4

1 に答える 1

5

latex.sパッケージのコードを確認する時間はありませんが、Hmisc確認するまでは、自由にチャンクをセンタリング環境にラップしてください。最もクリーンなソリューションではありませんが、仕事は完了します。

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

これにより、中央揃えのテーブルが生成されます。

于 2013-05-07T09:06:58.627 に答える