由Latex()从Hmisc包和Knitr生成的Latex表的奇怪行为

时间:2014-03-14 09:33:26

标签: r latex knitr hmisc

我有一些代码用于在Knitr中制作表格。我手动输入了一些数字以使代码可重现。

Expenditure <- as.matrix(data.frame(c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84"),c("41","55","71","84")))
rownames(Expenditure) <- c("30000","40000","50000","60000")
colnames(Expenditure) <- as.character(seq(0,0.35,0.05)*100)
latex(Expenditure,
      n.cgroup=c(8), cgroup=c("Largest Historical Drawdown"),
      file="", 
      ctable=TRUE, caption="Shortfall Risk Table", caption.loc=c('top'), label="tab:SfRisk")

这给出了以下Latex代码:

%latex.default(Expenditure, n.cgroup = c(8), cgroup = c("Largest Historical Drawdown"),     file = "", ctable = TRUE, caption = "Shortfall Risk Table",     caption.loc = c("top"), label = "tab:SfRisk")%
\ctable[caption={Shortfall Risk Table}label=tab:SfRisk,pos=!tbp,]{lllllllll}{}{\FL
\multicolumn{1}{l}{\bfseries Expenditure}&\multicolumn{8}{c}{\bfseries Largest Historical Drawdown}\NN
\cline{2-9}
\multicolumn{1}{l}{}&\multicolumn{1}{c}{0}&\multicolumn{1}{c}{5}&\multicolumn{1}{c}{10}&\multicolumn{1}{c}{15}&\multicolumn{1}{c}{20}&\multicolumn{1}{c}{25}&\multicolumn{1}{c}{30}&\multicolumn{1}{c}{35}\ML
30000&41&41&41&41&41&41&41&41\NN
40000&55&55&55&55&55&55&55&55\NN
50000&71&71&71&71&71&71&71&71\NN
60000&84&84&84&84&84&84&84&84\LL
}

这会产生一个Latex表,但是标题的末尾添加了“label”这个词,因此它表示“Shortfall Risk Tablelabel”。 “Tablelabel”一词不会出现在.tex文档中的任何位置。我已经找到了解决方案,但我找不到任何东西。任何帮助非常感谢!

我无法发布图像,因为我显然没有足够高的“声誉”。所以我在johnbutters.org/examples

放了一个

1 个答案:

答案 0 :(得分:2)

根据cbeleites的评论,这是来自latex()函数的ctable代码的问题。解决方案是&#34; ctable = FALSE&#34;。这仍然会给出略微奇怪的输出行:&#34; \ caption {Shortfall Risk Table \ label {tab:SfRisk}}&#34;但最终输出看起来还不错。