上图的标题使用 knitr (LaTeX/PDF) [英] Caption above figure using knitr (LaTeX/PDF)

查看:23
本文介绍了上图的标题使用 knitr (LaTeX/PDF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 texmaker 中使用 knitr 将标题放在图上方.我知道这个问题已经被问过了,并且我知道到目前为止建议的解决方案是使用:

I would like to place the caption above the figure using knitr in texmaker. I know that this question has already been asked, and I understand that the solution suggested so far is to use:

egin{figure} 
caption{This is a caption above the figure} 
<<a-plot, echo=FALSE>>= 
plot(1) 
@ 
end{figure} 

但这样我无法显示代码(因为 echo=FALSE).如果我选择 echo=TRUE,我得到的是标题,然后是代码,然后是图表,这也不是我想要的.我想展示的是 R 的代码,(and)用该 R 代码绘制的图形,带有标题 在图表上方.

But in this way I cannot show the code (since echo=FALSE). And if I choose instead echo=TRUE, what I get is the caption, then the codes, and then the graph, which is also not what I want. What I would like to show is the code for R, (and) the graph plotted with that R code, with the caption above the graph.

推荐答案

尝试使用钩子:

<<include=FALSE>>=
f <- function(x, options) {
  paste("\end{kframe}
", 
        "\caption{", options$capT, "}
", 
        hook_plot_tex(x, options), 
        "
\begin{kframe}", sep = "")
}
knit_hooks$set(plot = f)
@

egin{figure} 
<<a-plot, echo=TRUE, capT="cap, cap, and cap">>= 
plot(1) 
@ 
end{figure} 

这篇关于上图的标题使用 knitr (LaTeX/PDF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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