Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding floating xtable in knitr hides the caption of the table

Tags:

r

knitr

I am using knitr to create the output of the table. The problem here is when I try to avoid float to the xtable the caption doesn't appear. The option I used to avoid float is floating="F" in print(xtable)

I have the following sample code used on the knitr.

\documentclass[12pt,Arial]{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage[left=0.7in, right=0.8in, bottom=0.6in, top=0.8in]{geometry}
\usepackage{float}

\begin{document}
\section{start}
<<comment=NA,results='asis',echo=FALSE>>=
library(xtable)
jd1 <- structure(c(23.16, 27.14, 31.03, 30.11, 33.03, 38.78, 23.45, 
26.96, 30.93, 29.85, 32.53, 35.99, -2.965, -0.1998, 0.08065, 
0.2588, 0.5829, 6.042, 0.0001466, 0.1369, 0.3252, 0.629, 0.9057, 
6.042), .Dim = c(6L, 4L), .Dimnames = list(c("Min.", "1st Qu.", 
"Median", "Mean", "3rd Qu.", "Max."), c("observed", "modeled", 
"obsdmod", "aobsdmod")))
names(jd1)<- c("Observed","Modeled","Observed-Modeled","|Observed-Modeled|")
print(xtable(jd1,caption="Summary of table for observed and modeled temperatures at station T1"),type="latex",floating="F")
@
\end{document}
like image 637
Jd Baba Avatar asked Jul 06 '13 02:07

Jd Baba


1 Answers

Yes, only floats have captions. If it's not floating, you'll have to use some other mechanism to document it. Maybe just put text immediately before it telling what it is?

It does feel, though, like you're not really asking the question you want to ask. Why don't you want it to float? If you want it to look like a float, but don't want LaTeX to have any say in the placement, there are better methods.

EDIT: Aha, I thought so. You can achieve \begin{table}[H] with the table.placement option.

> print(xtable(cbind(1,2)), table.placement="H")
% latex table generated in R 2.15.1 by xtable 1.7-0 package
% Sat Jul  6 08:06:52 2013
\begin{table}[H]
...
like image 94
Aaron left Stack Overflow Avatar answered Nov 16 '22 01:11

Aaron left Stack Overflow