Ser*_*ena 7 latex caption texmaker knitr
我想在texmaker中使用knitr将标题放在图上方. 我知道这个问题已经被提出,我理解到目前为止建议的解决方案是使用:
\begin{figure}
\caption{This is a caption above the figure}
<<a-plot, echo=FALSE>>=
plot(1)
@
\end{figure}
Run Code Online (Sandbox Code Playgroud)
但是这样我就无法显示代码(因为echo=FALSE).如果我选择echo=TRUE,我得到的是标题,然后是代码,然后是图表,这也不是我想要的.我想要展示的是代码R,(和)用该R代码绘制的图表,图表上方的标题.
我倾向于使用LaTeX软件包来实现这样的自定义:Tex StackExchange上有一个庞大的社区,他们已经开发出解决类似问题的方法。
该floatrow程序包可用于将标题重新放置在图形上方。这很大程度上基于先前的答案。
使用R Markdown,因为这是近来最常用的工作流程,可以通过header-includes在YAML中包含参数来加载程序包,如下所示:
---
output: pdf_document
header-includes:
- \usepackage{floatrow}
- \floatsetup[figure]{capposition=top}
---
```{r fig.cap="cap, cap, and cap"}
plot(1)
```
Run Code Online (Sandbox Code Playgroud)
输出具有所需的顺序,首先显示代码,然后显示标题,然后显示图形。
如果不需要该代码,则echo=FALSE可以将该选项添加到块头中。
尝试使用钩子:
<<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}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
1736 次 |
| 最近记录: |