简体   繁体   English

在 R markdown 中对齐左图标题

[英]align left figure caption in R markdown

figure captions in R markdown to PDF are centered by default. R markdown to PDF 中的图标题默认居中。 here's an example:这是一个例子:

---
title: "test"
output: pdf_document
---


![Caption](test_pic.jpg)

(where test_pic.jpg is a local jpg file) (其中test_pic.jpg是本地 jpg 文件)

any ideas how to align the caption left?任何想法如何将标题左对齐?

I found how to change the size, using special attributes:我找到了如何使用特殊属性更改大小:

![Caption](test_pic.jpg){#id .class width=30%} 

but what's the special attribute to align left?但是左对齐的特殊属性是什么?

Yes, to align the caption left in PDF output from Rmarkdown we can use one chunk per image, with knitr::include_graphics in the chunk to display the image (this creates the LaTeX for the image), and a little LaTeX that controls the alignment of the caption:是的,要对齐 Rmarkdown 输出的 PDF 中留下的标题,我们可以在每个图像中使用一个块,在块中使用knitr::include_graphics来显示图像(这会为图像创建 LaTeX),以及一个控制对齐的小 LaTeX标题:

---
title: "Untitled"
output:
    pdf_document:
        includes:
            in_header: file.tex
---

Here are some examples of `knitr::include_graphics` with the code chunk options being used to control the size and location:

```{r fig.align="left",  out.width = "50%", fig.cap="left-aligned"}
knitr::include_graphics("rrtools-steps-carbon.png")
```

```{r fig.align="center",  out.width = "30%", fig.cap="center aligned"}
knitr::include_graphics("rrtools-steps-carbon.png")
```

```{r fig.align="right",  out.width = "20%", fig.cap="right aligned"}
knitr::include_graphics("rrtools-steps-carbon.png")
```

And here is file.tex , which should be in the same directory as the RMarkdown file:这是file.tex ,它应该与 RMarkdown 文件在同一目录中:

\usepackage[font=small,format=plain,labelfont=bf,up,textfont=normal,up,justification=justified,singlelinecheck=false]{caption}

And here's a screenshot of part of the output:这是部分输出的屏幕截图:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM