reveal.js幻灯片中RMarkdown代码块的高度
我不断遇到幻灯片中代码块溢出的问题,因此不得不在幻灯片中滚动。不适合教学reveal.js幻灯片中RMarkdown代码块的高度,r,knitr,r-markdown,pandoc,reveal.js,R,Knitr,R Markdown,Pandoc,Reveal.js,我不断遇到幻灯片中代码块溢出的问题,因此不得不在幻灯片中滚动。不适合教学 如何在逐块的基础上使代码块更高(或更宽) js或其他html格式中的一个如何改变代码文本的大小,同样是在逐块的基础上。我知道在全球范围内我可以改变CSS中的内容,但我希望更具动态性 p、 如果有人想知道如何在不影响其他幻灯片元素的情况下更改中心文本的行为,请在最近对其进行故障诊断,这是不寻常的,但可行的。使用CSS自定义代码块 您可以使用fenced_code_attributes将CSS类(或几个不同的类)添加到某些代码
fenced_code_attributes
将CSS类(或几个不同的类)添加到某些代码块中。为此,您可以将此选项添加到YAML标头中,并使用knit\u hoooks$set()
(有关详细信息,请参阅)。之后,我们可以使用chunk选项class='myCssClass'
在下面的示例中,我们定义了一个类.smallCode
,它为块设置了一定的宽度和较小的字体大小。在最终文档中,结果如下所示:
<pre class="sourceCode r smallCode">
<code class="sourceCode r">
THE CODE WE PRODUCED
</code>
</pre>
这是我们刚刚定制的代码块的屏幕截图:
我更新了我的答案。希望这能满足您的需要。在本例中,高度会自动调整。对于200px使用
高度:200px已更改答案。现在我也改变了块的高度。嗯-是的,如果我把样式放在.Rmd中。如果我将样式放在styles.css文件中,则不会。奇怪的
---
title: "Customized Code Chunks"
author: Martin Schmelzer
date: March 22, 2005
output:
revealjs::revealjs_presentation:
md_extensions: +fenced_code_attributes
---
<style>
pre.smallCode {
width: 360px; /* Change the width of the chunk */
height: 360px; /* Change the height of the chunk */
font-size: 0.4em; /* Change the font-size */
background-color: lightgrey; /* Change background color */
}
</style>
```{r, include=FALSE}
knitr::knit_hooks$set(source = function(x, options) {
return(paste0(
"```{.r",
ifelse(is.null(options$class),
"",
paste0(" .", gsub(" ", " .", options$class))
),
"}\n",
x,
"\n```"
))
})
```
# Customized Code Chunks
## Example
<!-- Here we use the option tidy=TRUE with a cutoff after 40 characters -->
```{r, class = 'smallCode', tidy=T, tidy.opts=list(width.cutoff=40)}
df <- data.frame(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))
```