Rmarkdown的render()+ knitr的spin():如何混合代码块和嵌套项

lor*_*age 7 markdown r knitr r-markdown

我生成HTML和PDF格式的笔记本电脑从R使用-scripts rmarkdown的功能render()knitr的功能spin().有时我使用嵌套列表并将它们与代码块混合使用.以下是使用rmarkdownknitr块选项的示例.

#' (1) This is normal text.
#'    (a) This is normal text but indented.
#+ echo = TRUE, eval = TRUE 
print("This is code")
#'    (b) This is supposed to be normal text with the same
#'        indentation as (a). However, it will be formatted as code.
#'        By this I mean that e.g. in a pdf-notebook it will be 
#'        correctly indented but the font will be the same font as 
#'        the code.
Run Code Online (Sandbox Code Playgroud)

但是,列表项(a)之后的代码后面的所有内容也将被标记为代码(例如(b)).但我想要实现的是将(b)标记为普通文本并使用与(a)相同的缩进.是否有可能做到这一点?

Yih*_*Xie 4

有一个内部块选项indent可以向块输出添加缩进。在您的情况下,您可以指定四个空格,例如

#+ echo = TRUE, eval = TRUE, indent = '    '
Run Code Online (Sandbox Code Playgroud)