在knitr

时间:2016-05-18 14:57:32

标签: r latex knitr rnw

在LaTeX中使用knitr环境时,有没有办法在figure中将代码和图形保持在一起?

这种风格:

\documentclass{article}
\begin{document}
writing
<<cars, fig.cap="this is a figure.">>=
with(mtcars, plot(mpg, disp))
@
writing
\end{document}

会导致数字在LaTeX中浮动 - 这就是我想要的,除了数字可以float away from the code

我目前的解决方法是手动在LaTeX中编写图形环境:

\begin{figure}
<<cars2>>=
with(mtcars, plot(mpg, disp))
@
\caption{this is a figure.}
\end{figure}

我可以在knitr中执行更优雅的方式吗?添加fig.pos='h'选项是不够的。 fig.show='asis'也无法完成任务。

我必须自己编写钩子吗?这可能是done easily吗?

0 个答案:

没有答案