【问题标题】:Rmarkdown font size and headerRmarkdown 字体大小和标题
【发布时间】:2015-08-07 10:33:43
【问题描述】:

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

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 脚本中我做了以下操作:

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

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

【问题讨论】:

  • 我相信fontsizermarkdown(不是knitr)中的纯LaTeX 元数据变量,如rmarkdown.rstudio.com 所示。 (我的 Rstudio 版本——0.98.1103——不包括那个选项,你是修改了文档的 YAML 头还是从不同的包中获取了模板?)也许你可以看看customizing the CSS

标签: css r fonts r-markdown


【解决方案1】:

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

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

---
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

更新:

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

【讨论】:

  • code.rpre 不适合我;代码改了吗?
  • 不确定,我早上看看,你用的是什么操作系统和浏览器?
  • 刚刚想通了,我加载了另一个主题,这显然妨碍了我。很抱歉,感谢您的快速回复。
  • 我在2019年5月使用。标题有警告信息:“元素(h1.title)被过度限定,只需使用不带元素名称的.title”。 h1 元素还有一个附加警告:“标题 h1 已定义。”将 h1.title 更改为 .title 后,两个警告都会消失。
  • 我有一个问题:这适用于 power point 演示文稿吗?
猜你喜欢
  • 2019-10-09
  • 2017-12-14
  • 2016-09-05
  • 2017-12-15
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 2011-09-03
  • 1970-01-01
相关资源
最近更新 更多