在RMarkdown HTML输出中更改数字字幕的字体大小 [英] Changing the font size of figure captions in RMarkdown HTML output
问题描述
我想让我的R Markdown文档中的所有图形标题的字体大小更小。最终的输出是HTML,我正在R Studio工作。为了加载图片,我使用 knitr
中的 include_graphics
函数,因为我被告知这是最好的方法请参阅
正如您所看到的,标题字体大小和常规文本字体大小完全相同,看起来不太好。如何解决这个问题?
只需将以下CSS添加到Rmd文档(YAML标题下的任意位置):
< style>
p.caption {
font-size:0.6em;
}
< / style>
我们在这里做什么:
如果您在浏览器中标记标题并检查该元素(Chrome:右键单击 - > Inspect),则可以看到标题实际上是一个HTML段落,其类名为标题
:
< p class =caption> ...< / p>
使用上面的CSS代码,我们将这些元素的字体大小(仅限于那些)更改为60%的默认大小。
I would like to make the font size of all figure captions in my R Markdown document smaller. The final output is HTML 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: "July 4, 2017"
output:
html_document:
fig_caption: yes
---
```{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:
As you can see, the caption font size and the regular text font size are exactly the same, which doesn't look that nice. How can I solve this problem?
Just add the following CSS to your Rmd document (anywhere below the YAML header):
<style>
p.caption {
font-size: 0.6em;
}
</style>
What are we doing here:
If you mark the caption in your browser and inspect that element (Chrome: right-click -> Inspect) you can see that the caption is actually a HTML paragraph with a class named caption
:
<p class="caption"> ... </p>
With the above CSS code we change the font-size of exactly those elements (and only those) to 60% of the default size.
这篇关于在RMarkdown HTML输出中更改数字字幕的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!