如何添加表格r包的标题? [英] How to add caption with the tables r package?

查看:298
本文介绍了如何添加表格r包的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用虹膜数据,我们用包创建一个表:

 <$ (表格)(表格((Sepal.Length + Sepal.Width)〜
格式(format(digits = 2))*(mean + sd),data =虹膜)

使用 Hmisc 将像乳胶这样的函数添加标题:

  latex( table,caption =My table)

但是这对包,因为它定义了一个S3方法, latex.tabular



所以我已经尝试过了,下面是一个包装小插曲的例子。 :

  latex(table,options = list(toprule =\\ caption {My table}))

但是它不起作用,它说标题在浮动之外。我怎样才能从包中的 latex.tabular 函数正确添加标题?

$ b $我想出了一种方法来做到这一点,这实际上很简单:你只需要嵌入

knitr 的一个例子中,<< >> =< / code>是 r 块代码。

  \ begin {table} 
\ caption {我从表格包中得到真棒表}
\ begin {center}

latex(table)
@
$ b \ end {center}
\label { tab:mytable}
\ end {table}

与标题(葡萄牙语):

Using the iris data, we make a table with the tables package:

library(tables)
table <- tabular( (Sepal.Length+Sepal.Width) ~
           Format(format(digits=2))*(mean + sd), data=iris )

With the Hmisc package, we would add the caption with the latex function like this:

latex(table, caption="My table")

But that does not work with the tables package, because it defines an S3 method, latex.tabular.

So I have tried this, following an example in the package vignette:

latex(table, options=list(toprule="\\caption{My table}"))

But it does not work, it says that caption is outside float. How can I correctly add caption with the latex.tabular function from the tables package?

解决方案

I figured out one way to do it and it is actually pretty easy: you just have to embed the tables package result inside the latex code.

Below one example with knitr, the << >>= is the r chunk code.

\begin{table}
\caption{My awesome table from tables package}
\begin{center}

<<cool multilevel table, results='asis', echo=FALSE>>=
latex(table)
@

\end{center}
\label{tab:mytable}
\end{table}

This generated this awesome table, now with title (in portuguese):

这篇关于如何添加表格r包的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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