Put tables and graphs in the right place (Sweave document)

1,620 views
Skip to first unread message

José Fernando Zea Castro

unread,
Nov 12, 2013, 9:02:21 PM11/12/13
to kn...@googlegroups.com
Hello.

I've got some problems putting the tables and graphs (generated in R)  in a specific position in my document. I'm using a Sweave file.  The figures and tables appear in other pages and sometimes in different sections, There are a lot of solved questions about that issue for latex documents, but I can't find specific information for knitR.

Thank you in advance

José Zea
MSc in Statistics

Yihui Xie

unread,
Nov 13, 2013, 2:03:49 AM11/13/13
to José Fernando Zea Castro, knitr
There is nothing special in knitr -- just use the LaTeX tricks you
found to solve the floating problem, which is very common and in some
cases not trivial to solve in LaTeX.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

José Fernando Zea Castro

unread,
Nov 13, 2013, 10:20:41 AM11/13/13
to kn...@googlegroups.com
Thank you, but are there some options in the chunks to place in the desired place the figures and tables?, for example those two chunks:

<<tabla1b, echo = FALSE, results = 'asis'>>=
xtable(table1, caption ="titletable1", label = 'MyT1')
@


<<figura1 fig.lp="figura1:", fig.cap = 'Title figure',echo=FALSE >>=
boxplot(y ~ group)
@

Yihui Xie

unread,
Nov 13, 2013, 4:05:48 PM11/13/13
to José Fernando Zea Castro, knitr
It is hard to define the "desired" place for floating environments in
LaTeX. It is a problem that bothers many people and there are also
many "solutions", as you have realized. The float package is one of
them, corresponding the "H" position. See one example here:

https://github.com/yihui/knitr-examples/blob/master/067-graphics-options.Rnw

fig.pos="H" only works for figures, of course. For tables, it depends
on which R package you use; the position may or may not be supported.
In typesetting, I believe "many tables and figures" almost surely ends
up in a mess due to the restriction of pages:
http://yihui.name/en/2013/10/markdown-or-latex/ The solution does not
even exist in theory as long as this restriction is there.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


Reply all
Reply to author
Forward
0 new messages