renger at vannieuwkoop.ch
2011-Nov-18 08:33 UTC
[R] xtable and sweave: caption placement problem
Dear All
I am running Sweave with xtable and want to put the caption placement
on top. But this does not work. Any idea what is going wrong?
Here is an example that runs properly with the exception of the
caption placement in the pdf-file.
\documentclass[11pt,a4paper]{article}
\usepackage{Sweave}
\begin{document}
<<>>x = runif(100, 1, 10)
y = 2 + 3 * x + rnorm(100)
@
<<echo=FALSE,results=tex>>library(xtable)
print(xtable(summary(lm(y~x)),
align="rcccc",
caption="Summary statistics for the regression model",
caption.placement="top", label="tab:summary",
digits=2))
@
\end{document}
Renger
_________________________________________
Renger van Nieuwkoop
Centre for Energy Policy and Economics, ETH Z?richbergstrasse 18 (ZUE)
CH - 8032 Z?rich
+41 44 632 02 63
mailto: renger at vannieuwkoop.ch
blog.modelworks.ch
Dear Renger,
This is occurring because "xtable" divides up the arguments into items
related to the "content" of the table and arguments related to the
"layout" of the table.
The "caption.placement" is an argument to "print.xtable()"
rather than to "xtable()":
print(xtable(summary(lm(y~x)),
align="rcccc",
caption="Summary statistics for the regression model",
label="tab:summary",
digits=2),
caption.placement="top")
If you have any additional questions, feel free to contact me.
Best regards,
Charlie Roosen
xtable maintainer
Charles Roosen, PhD
Technical Director
Mango Solutions AG
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of renger at vannieuwkoop.ch
Sent: 18 November 2011 09:33
To: r-help at r-project.org
Subject: [R] xtable and sweave: caption placement problem
Dear All
I am running Sweave with xtable and want to put the caption placement
on top. But this does not work. Any idea what is going wrong?
Here is an example that runs properly with the exception of the
caption placement in the pdf-file.
\documentclass[11pt,a4paper]{article}
\usepackage{Sweave}
\begin{document}
<<>>x = runif(100, 1, 10)
y = 2 + 3 * x + rnorm(100)
@
<<echo=FALSE,results=tex>>library(xtable)
print(xtable(summary(lm(y~x)),
align="rcccc",
caption="Summary statistics for the regression model",
caption.placement="top", label="tab:summary",
digits=2))
@
\end{document}
Renger
_________________________________________
Renger van Nieuwkoop
Centre for Energy Policy and Economics, ETH Z?richbergstrasse 18 (ZUE)
CH - 8032 Z?rich
+41 44 632 02 63
mailto: renger at vannieuwkoop.ch
blog.modelworks.ch
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
LEGAL NOTICE
This message is intended for the use o...{{dropped:10}}
It works if you separate the print command and put the caption placement in
the print command
, see below:
\documentclass[11pt,a4paper]{article}
\usepackage{Sweave}
\begin{document}
<<>>x = runif(100, 1, 10)
y = 2 + 3 * x + rnorm(100)
@
<<echo=FALSE,results=tex>>library(xtable)
p <- (xtable(summary(lm(y~x)),align="rcccc",
caption="Summary statistics for the regression model",
label="tab:summary", digits=2))
print( p, caption.placement="top" )
@
\end{document}
Rgds,
Rainer
On Friday 18 November 2011 09:33:07 renger at vannieuwkoop.ch
wrote:> Dear All
>
> I am running Sweave with xtable and want to put the caption placement
> on top. But this does not work. Any idea what is going wrong?
>
> Here is an example that runs properly with the exception of the
> caption placement in the pdf-file.
>
> \documentclass[11pt,a4paper]{article}
> \usepackage{Sweave}
> \begin{document}
> <<>>> x = runif(100, 1, 10)
> y = 2 + 3 * x + rnorm(100)
> @
>
> <<echo=FALSE,results=tex>>> library(xtable)
> print(xtable(summary(lm(y~x)),
> align="rcccc",
> caption="Summary statistics for the regression model",
> caption.placement="top", label="tab:summary",
> digits=2))
>
> @
>
> \end{document}
>
>
> Renger
>
>
> _________________________________________
> Renger van Nieuwkoop
> Centre for Energy Policy and Economics, ETH Z?richbergstrasse 18 (ZUE)
> CH - 8032 Z?rich
> +41 44 632 02 63
> mailto: renger at vannieuwkoop.ch
> blog.modelworks.ch
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.