Rmarkdown 字体大小和标题 [英] Rmarkdown font size and header

查看:232
本文介绍了Rmarkdown 字体大小和标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近打开了一个标准的 Rmd 文件,没有进行任何编辑.默认文件如下所示:

I recently opened a standard Rmd file without editing anything. The default file looks like this:

Untitled.rmd

---
title: "myfile"
author: "Me"
date: "May 25, 2015"
output: html_document
fontsize: 12pt
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

我想创建一个与上述文件相对应的 html 文件,因此在单独的 R 脚本中,我执行了以下操作:

I wanted to create an html file corresponding to the above file so in a separate R script I did the following:

knit('Untitled.Rmd', 'doc.md')
markdownToHTML('doc.md', 'testing.html',header = TRUE)

由于某种原因字体大小不起作用,我希望的标题信息没有出现在我的 testing.html 中.有人知道为什么会这样吗?

For some reason the font size doesn't work and the header information that I was hoping for doesn't appear in my testing.html. Anyone know why this is happening?

推荐答案

这是我用来控制 R-markdown 文件中字体大小和颜色的方法.它基本上覆盖了 CSS 样式表,而无需创建新文件.该示例更改了标题和标题的大小,以及内嵌文本和 R 代码文本,并设置了一些颜色.

This is what I used to control font size and color in an R-markdown file. It basically overrides the CSS style sheets without having to create a new file. The example changes the sizes of the headers and titles, as well as the inline text and the R-code text, and sets some colors as well.

就我而言,我需要将更多信息打包到具有指定页数的文档中,因此我将所有内容都缩小了.

In my case I needed to pack more information into a document that had a specified number of pages so I made everything smaller.

---
title: "This is a title"
date: 25 May 2015
output:
html_document:
theme: cerulean
---

<style type="text/css">

body{ /* Normal  */
      font-size: 12px;
  }
td {  /* Table  */
  font-size: 8px;
}
h1.title {
  font-size: 38px;
  color: DarkRed;
}
h1 { /* Header 1 */
  font-size: 28px;
  color: DarkBlue;
}
h2 { /* Header 2 */
    font-size: 22px;
  color: DarkBlue;
}
h3 { /* Header 3 */
  font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: DarkBlue;
}
code.r{ /* Code block */
    font-size: 12px;
}
pre { /* Code block - determines code spacing between lines */
    font-size: 14px;
}
</style>


# H1 Header

Some body text

## H2 Header

More body text

### H3 Header

blah blah blah

```{r echo=T}
n <- 100
df <- data.frame(x=rnorm(n),y=rnorm(n))
```

### Another H3

更新:

添加了更多样式、评论和一点颜色,使这个答案更有用.和屏幕截图:

Update:

Added more more styles, comments, and a bit of color to make this answer more useful. And a screen shot:

这篇关于Rmarkdown 字体大小和标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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