我已经使用编织器几天了,太好了! :)
目前,我正在努力在输出文件(PDF)中将两个图彼此对齐。根据我的理解,应该通过设置out.width='.4\\linewidth'
或chunk-options中的类似选项来实现。
生成的图非常小,可以很容易地将2个图彼此相邻放置,但是无论如何,将所有图放置在彼此之下。
我也很难将 latex 表(xtable
-output与results='asis'
-option)对齐到文档的左侧。最好写在它旁边。
最佳答案
由于您还没有提供,我将为您提供:
\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}
再一次,我只是简单地修改了在tex.stackexchange.com网站上this问题中发现的代码。
关于r - 使用knitr将图彼此对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10574552/