Question

I have some code that I am using to make a table in Knitr. I have typed in some numbers manually to make the code reproducible.

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")

This gives the following Latex code:

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

This produces a Latex table, but the caption has had the word "label" added to the end, so it says "Shortfall Risk Tablelabel". The word "Tablelabel" does not appear anywhere in the .tex document. I have searched for a solution to this but I can't find anything. Any help much appreciated!

I can't post an image because I don't have a high-enough "reputation", apparently. So I have put one at johnbutters.org/examples

Was it helpful?

Solution

As per cbeleites's comment, it's a problem with the ctable code that comes out of the latex() function. The solution is to have "ctable=FALSE". This still gives the slightly odd output line: "\caption{Shortfall Risk Table\label{tab:SfRisk}}" but the final output looks OK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top