由于您还没有提供,我会为您提供:
\documentclass{article}
\begin{document}
Side by side images:
\begin{figure}[htpb]
<<myChunk, fig.width=3, fig.height=2.5, out.width='.49\\linewidth', fig.show='hold'>>=
par(mar=c(4,4,.1,.1),cex.lab=.95,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3)
plot(cars)
boxplot(cars$dist,xlab='dist')
@
\end{figure}
Ta da!
\end{document}
当我运行 knitr 时,这对我来说大致如下:
注意摆弄par 设置以确保一切看起来都不错。你将不得不修补。
这个最小的可重现示例来自 knitr 网站上非常详细的 examples。
编辑
要回答您的第二个问题,尽管它更像是一个纯 LaTeX 问题,但这里是一个最小的示例:
\documentclass{article}
\usepackage{wrapfig,lipsum}
%------------------------------------------
\begin{document}
This is where the table goes with text wrapping around it. You may
embed tabular environment inside wraptable environment and customize as you like.
%------------------------------------------
\begin{wraptable}{l}{5.5cm}
\caption{A wrapped table going nicely inside the text.}\label{wrap-tab:1}
<<mychunk,results = asis,echo = FALSE>>=
library(xtable)
print(xtable(head(cars)),floating = FALSE)
@
\end{wraptable}
%------------------------------------------
\lipsum[2]
\par
Table~\ref{wrap-tab:1} is a wrapped table.
%------------------------------------------
\end{document}
再一次,我只是修改了我在 amazingly 有用的 tex.stackexchange.com 站点上的 this 问题中找到的代码。