我一直在使用knitr几天,这太棒了!:)
目前,我正努力在输出文件(PDF)中将两个图拼接在一起.根据我的理解,这应该通过out.width='.4\\linewidth'在块选项中设置或类似的东西来实现.
由此产生的图很小,2很容易彼此相邻,但不知何故,所有图都放在彼此之下.
我也很难将latex-tables(xtable-output和results='asis'-option)对齐到文档的左侧.在旁边写它会很棒.
jor*_*ran 18
由于您没有提供,我将为您这样做:
\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}
Run Code Online (Sandbox Code Playgroud)
当我运行knitr时,这会产生一些看起来像这样的东西:

请注意摆弄par设置以确保一切都很好看.你将不得不修补.
这个可重复性最小的例子来自knitr网站上非常详细的例子.
编辑
要回答你的第二个问题,即使它更像是一个纯粹的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}
Run Code Online (Sandbox Code Playgroud)
再一次,我只是在非常有用的tex.stackexchange.com网站上修改了我在这个问题中找到的代码.
| 归档时间: |
|
| 查看次数: |
6323 次 |
| 最近记录: |