Position of plots using knitr

拈花ヽ惹草 提交于 2019-12-23 01:22:13

问题


Consider these two chunks:

\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)
@

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.

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

I try this solution:

\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.

Thanks a lot

Marc


回答1:


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)
@


来源:https://stackoverflow.com/questions/22740643/position-of-plots-using-knitr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!