6

最初に、私が間違っている場合に備えて、私が全体像を把握しようとしていることを説明します。knitrを使用してRStudio内にLaTeXテーブルとして出力したいネストされたテーブルがあります。キャプションを追加するまでは大丈夫です。9ページのtablesビネット(LINK)の例を試してみました。

キャプションがなくても機能しますが、キャプションを追加しても機能しません。また、非表形式のオブジェクトでも機能します。面白いことに、それはlatex.default機能しますが、RStudio /knitrのCompilePDFでエラーが発生し、私が読んだものからlatexとにかく呼び出されます。さらに、テーブルは適切に丸められなくなりました。試しlatexTabularましたが、それも適切に丸められていません。

library(Hmisc); library(tables)
latex(head(mtcars), file="", caption="de")   #works

x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
         (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )

latex(x, file="", caption="de") #no caption :(

理想的には、出力に含めることができるようにしたいのです\caption{de}が、どこが間違っているのか理解できません。

これが役立つ場合は、ここに入力と出力があります。

> latex(x, file="", caption="de", label="tab1") 
\begin{tabular}{lccccc}
\hline
 &  & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ 
Species  & n & mean & sd & mean & sd \\ 
\hline
setosa  & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\
versicolor  & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\
virginica  & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\
All  & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\
\hline 
\end{tabular}
4

3 に答える 3

9

私はこれを認めるのが恥ずかしいですが、全体の問題は、属していないコードチャンク内に何かを強制しようとしたことでした。私は将来の検索者を助けるために自分のプライドを窒息させています。ラテックスのものは外側に行きます。したがって、上記のテーブルを適切にフォーマットされたテーブルとしてプロットしようとしている場合、これが探しているものです。

\begin{table}[ht]
\caption{This is a sample caption. \label{guy}}
<<desc, echo = FALSE, results = 'asis'>>=
x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
     (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )
latex(x)
@
\end{table}
于 2012-09-13T03:51:39.500 に答える
7

tabular()のxオブジェクトはクラス'tabular'であり、caption引数のないlatex.tabularにディスパッチされています。意図されたユースケースは、キャプションの提供を任務とするSweave内にあると思います。

ただし、22ページ"\\caption{.}"に、テーブルビネットのオプションの引数を使用する例があります。これは成功をもたらすようです:

 x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
          (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )

 latex(x, file="", options = list( tabular="longtable", toprule="\\caption{This is a sample caption.}\\\\   \\toprule",  midrule="\\midrule\\\\[-2\\normalbaselineskip]\\endhead\\hline\\endfoot"))
\begin{longtable}{lccccc}
\caption{This is a sample caption.}\\   \toprule
 &  & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ 
Species  & n & mean & sd & mean & sd \\ 
\midrule\\[-2\normalbaselineskip]\endhead\hline\endfoot
setosa  & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\
versicolor  & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\
virginica  & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\
All  & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\
\hline 
\end{longtable}
于 2012-09-13T01:30:47.143 に答える
0

これは機能するはずです。

cat('\\begin{table}[ht]
    \\centering')
latex(tabularTable)
cat('\\caption{some caption}')
cat('\\label{tab:table1}')
cat('\\end{table}')
于 2015-08-29T09:02:27.407 に答える