R Markdown PDF中上图的图标题 [英] Fig caption above figure in R Markdown PDF

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

问题描述

我想知道如何使字幕显示在R Markdown中的图形上方.

这是一个可行的示例:

  ---标题:实用"输出:pdf_document:fig_caption:是的latex_engine:xelatex---```{r fig1,echo = FALSE,fig.cap ="\\ label {fig:fig1}标题"}x <-1:10y<-11:20情节(x,y)``` 

I was wondering how I could get my captions to appear above my figures in R Markdown.

Here is a working example:

---
title: "Practical"
output:
  pdf_document:
    fig_caption: yes
    latex_engine: xelatex
---

```{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}Caption"}
x <- 1:10
y <- 11:20
plot(x, y)
```

The question has been asked before here, but the code suggested does not seem to work for me.

解决方案

When RMarkdown is run, it converts the base document to a LaTeX document using pandoc. As a result, we LaTeX packages can be used within the document, which can help in achieving advance customisation like this.

In this case, the Floatrow package can be used to reposition the caption above the figure. This is largely based of this previous answer. It can be loaded by including header-includes argument within the YAML, as follows:


title: "Practical"
output:
  pdf_document:
    fig_caption: yes
    latex_engine: xelatex
header-includes:
   - \usepackage{floatrow}
   - \floatsetup[figure]{capposition=top}
---


```{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}Caption"}
x <- 1:10
y <- 11:20
plot(x, y)
```

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

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