首先,我会告诉你我正在尝试做些什么,以防万一我做错了。我有一个嵌套表,我想在 RStudio 中使用 knitr 将其作为 LaTeX 表输出。我很好,直到我尝试添加标题。tables
我在小插图(LINK)中尝试了第 9 页上的示例。
它可以在没有标题的情况下使用,但是当我添加标题时它不会。它也适用于非表格对象。有趣的是,它latex.default
可以工作,但会导致 RStudio/knitr 的编译 PDF 出现错误,并且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}