CSS Rmarkdown 字体大小和标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30446905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:13:01  来源:igfitidea点击:

Rmarkdown font size and header

cssrfontsr-markdown

提问by theamateurdataanalyst

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

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

Untitled.rmd

无题.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.

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

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

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

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?

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

回答by Mike Wise

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.

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

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:

添加了更多样式、评论和一些颜色,以使此答案更有用。和屏幕截图:

enter image description here

在此处输入图片说明