使用编织器的情节位置 [英] Position of plots using knitr

查看:58
本文介绍了使用编织器的情节位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下两个部分:

\subsection{Section figure 1}
\begin{figure}[!h]
<<figure1>>=
plot(1, 1)
@
\caption{Figure 1}
\end{figure}

\newpage

\subsection{Section figure 2}
<<figure2, fig.cap="figure 2", fig.show='asis'>>=
plot(2, 2)
@

该图位于第一个块的"Section Figure x"标题之后,而在第二个块之前.但是,根据文档,在我看来这两个块应该相似.

The plot is located after the "Section figure x" title in the first chunk but before in the second one. However, based on documentation, it seems to me that these two chunks should be similar.

所以我的问题是:如何使用fig.cap ="figure 2"在标题部分后显示图.

So my question: how to show the plot after title section using fig.cap="figure 2".

我尝试此解决方案:

\subsection{Essai figure 2 bis}
\begin{figure}[!h]
\end{figure}
<<figure2bis, fig.cap="figure 2 bis", fig.show='asis'>>=
plot(2.5, 2.5)
@

但是它会生成一个页面,其中只有情节之前的部分标题.

But it generates a page with only the section title before the plot.

非常感谢

马克

推荐答案

您应该使用fig.pos标签将图形位置指定为块选项.在您的示例中,您可以执行以下操作:

You should specify the figure position as a chunk option using the fig.pos tag. In your example you can do the following:

\subsection{Section figure 2}
<<figure2, fig.cap="figure 2", fig.show='asis', fig.pos='!h'>>=
plot(2, 2)
@

这篇关于使用编织器的情节位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆