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

查看:82
本文介绍了上图的标题使用了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:

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

但是以这种方式,我无法显示代码(自echo=FALSE起). 如果我选择echo=TRUE,我得到的是标题,代码,图形,这也不是我想要的. 我想显示的是R,()用该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}\n", 
        "\\caption{", options$capT, "}\n", 
        hook_plot_tex(x, options), 
        "\n\\begin{kframe}", sep = "")
}
knit_hooks$set(plot = f)
@

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

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

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