As you said, that is caused by the alltt and verbatim environments for
the source code and output, respectively. Both environments add
vertical space around them by default. I just googled a while, and
found one solution for verbatim but not alltt:
http://tex.stackexchange.com/questions/43331/control-vertical-space-before-and-after-verbatim-environment
This solution alone won't work. I do not know how to remove the
vertical space for alltt. You may try StackExchange.
If you do not mind syntax highlighting, you can turn off the highlight
option, e.g.
<<highlight=FALSE>>=
A <- matrix(1:4, nrow=2)
A
@
Then everything will be in a single verbatim environment, and you will
no longer have the space problem.
Regards,
Yihui
--
Yihui Xie <
xiey...@gmail.com>
Web:
http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA