R Markdown - changing font size and font type in html output
我在RStudio中使用R Markdown和knit HTML选项创建HTML输出。但是,用于纯文本块的输出中使用的字体很小,我想将其更改为其他字体并增加字体大小。有人可以演示如何设置输出字体的示例吗?-无需大量的html知识就可以使用?
到目前为止,我已尝试在降价文档的顶部进行操作,但这不起作用。
1 2 3 | --- fontsize: 24pt --- |
我认为YAML中的
关于外观(不同的字体类型和颜色),您可以指定
我想,您正在寻找的是您自己的
1 2 3 4 5 | --- output: html_document: css: style.css --- |
在css文件中定义字体类型和大小:
1 2 3 4 5 6 7 8 9 | /* Whole document: */ body{ font-family: Helvetica; font-size: 16pt; } /* Headers */ h1,h2,h3,h4,h5,h6{ font-size: 24pt; } |
您可以使用HTML代码
例如:
1 2 3 4 5 6 7 8 9 10 11 | <font size="1"> This is my text number1</font> <font size="2"> This is my text number 2 </font> <font size="3"> This is my text number 3</font> <font size="4"> This is my text number 4</font> <font size="5"> This is my text number 5</font> <font size="6"> This is my text number 6</font> |
我肯定会使用html标记来实现这一目标。只需用
1 2 3 | <p style="font-family: times, serif; font-size:11pt; font-style:italic"> Why did we use these specific parameters during the calculation of the fingerprints? </p> |
这将产生以下输出
与
相比
这将与Jupyter Notebook和Typora一起使用,但是我不确定它是否通用。
最后,请注意html标记会覆盖Markdown使用的字体样式。
这些答案过于复杂。您只需使用html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | --- title:"Untitled" author:"James" date:"9/29/2020" output: html_document --- <style type="text/css"> body{ font-size: 12pt; } </style> ```{r setup, include = FALSE} knitr::opts_chunk$set(echo = TRUE) ``` |
要更改字体大小,您不需要了解很多html。使用记事本打开html输出。控件F搜索"字体大小"。您应该看到标题(h1,h2,h3,...)的字体大小的部分。
在此部分中的以下位置添加以下内容。
1 2 3 | body { font-size: 16px; } |
上面的字体大小是16 pt字体。您可以将数字更改为所需的任何数字。
我遇到了同样的问题,并通过以下方法解决了这一问题:1.制作style.css文件时,请确保您不只是将文本文件重命名为" style.css",请确保它确实是.css格式(例如,使用Visual Studio代码); 2.将该style.css文件与.rmd文件放在同一文件夹中。希望这对您有用。