Hmisc :: latex不打印带有表格对象的标题 [英] Hmisc::latex not printing caption w/ tabular object

查看:138
本文介绍了Hmisc :: latex不打印带有表格对象的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我将告诉您我尝试做的事情,以防万一我做错了.我有一个嵌套表,想使用knitr在RStudio中作为LaTeX表放出来.在尝试添加标题之前,我很好.我在tables插图(LINK)中的第9页上尝试了该示例.

First I will tell you what I'm attempting to do big picture in case I'm going about it wrong. I have a nested table that I'd like to out put as a LaTeX table within RStudio using knitr. I am fine until I try to add a caption. I tried the example on page 9 in the tables vignette (LINK).

它没有标题就可以工作,但是当我添加标题时却没有.它也适用于非表格对象.有趣的是,latex.default可以工作,但是会在RStudio/knitr的Compile PDF中导致错误,并且无论如何,我从latex读取的内容都会被调用;加上表格无法再四舍五入了.我尝试了latexTabular,但是也没有适当地四舍五入.

It works without the caption but when I add the caption it doesn't. It also works with a non tabular object. The funny thing is that latex.default works but causes an error in RStudio/knitr's Compile PDF and from what I read is called by latex anyway; plus the table isn't rounded appropriately anymore. I tried latexTabular but that isn't rounded appropriately either.

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},但无法弄清楚我要去哪里.

Ideally I'd want to be able to have \caption{de}in the output but can't figure out where I'm going wrong.

如果有帮助,请输入以下内容:

In case it's helpful here's the input and output:

> 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}

推荐答案

来自tabular()的x对象属于'tabular'类,将被分派到没有标题参数的latex.tabular.我猜想它的预期用例在Sweave内,它将负责提供标题.

The x object from tabular() is of class 'tabular' and is being dispatched to latex.tabular which has no caption argument. I'm guessing that it's intended use case is within Sweave which would be tasked with supplying the caption.

但是,在第22页上有一个示例,其中对表插图中的选项使用"\\caption{.}"自变量.这似乎产生了成功:

There is , however, an example on page 22 of using a "\\caption{.}" argument to options in the tables vignette. This seems to yield success:

 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}

这篇关于Hmisc :: latex不打印带有表格对象的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆