在RMarkdown Word输出中更改图形标题的字体大小 [英] Changing the font size of figure captions in RMarkdown Word output

查看:63
本文介绍了在RMarkdown Word输出中更改图形标题的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近问

很明显,此CSS方法不起作用(我猜它与HTML有关,因此无法在Word中呈现).在Word中,我可以手动更改每个标题的字体大小,但我希望设置一些全局R Markdown参数.有可能吗?

解决方案

几乎与HTML情况一样简单.以下内容适用于使用LibreOffice的工作流程.但是在Word中,它应该几乎是相同的:

  1. 生成您的docx输出文件.

  2. 在LibreOffice(或Word,或Pages,...)中打开它

  3. 在LibreOffice中,右键单击标题,然后选择"编辑样式" (在Word中,您可以使用 Ctrl + Shift + Alt + S 打开样式窗格)

  1. 在弹出的菜单中,您可以修改图像标题
  2. 的样式

  1. 完成样式的编辑后,单击"应用",然后将文件另存为名为 template.docx
  2. 的docx.

最后,在Rmd文档的YAML标头中添加样式引用,例如

 标题:"ppp"作者:"ppp"日期:"2017年7月4日"输出:word_document:reference_docx:template.docxfig_caption:是的 

根据您在参考文档中更改样式的方式,标题现在应该变小.

I recently asked

Changing the font size of figure captions in RMarkdown HTML output

and I got a very nice answer which uses this CSS method. I wanted to try the same, but this time with Word output. If you don't want to read my former question, I summarize the issue here: I'd like to make the font size of all figure captions in my R Markdown document smaller. The final output is Word,this time, and I'm working in R Studio. To load the picture, I use the include_graphics function from knitr, because I've been told it's the best way (see here). My .Rmd file is:

---
title: "ppp"
author: "ppp"
date: "`r Sys.Date()`"
output: 
  word_document: 
    fig_caption: yes
  html_document: 
    fig_caption: yes
---

<style>
p.caption {
  font-size: 0.8em;
}
</style>


```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = FALSE)
```


```{r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$"}
# All defaults
include_graphics("download.jpg")
```

This is regular text.

The corresponding output is:

Clearly, this CSS method doesn't work (I guess it's something related to HTML, so it doesn't render in Word). In Word I can manually change the font size for each caption, but I'd rather set some global R Markdown parameter. Is that possible?

解决方案

Almost as easy as in the HTML case. The following applies to the workflow using LibreOffice. But in Word it should be almost the same:

  1. Produce your docx output file.

  2. Open it in LibreOffice (or Word, or Pages, ...)

  3. In LibreOffice, right-click the caption and choose Edit Style (in Word you can open the styles pane with Ctrl+Shift+Alt+S)

  1. In the menu that popped up you can modify the style for Image Captions

  1. When you are done editing the style, click Apply and just save the file as a docx called template.docx

Finally, add a style reference in the YAML header of your Rmd document like

title: "ppp"
author: "ppp"
date: "July 4, 2017"
output: 
  word_document:
    reference_docx: template.docx
    fig_caption: yes

And the captions should be smaller now according to how you changed the style in your reference document.

这篇关于在RMarkdown Word输出中更改图形标题的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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