在YAML标头中的Rmarkdown html输出中对齐文本

我想对Rmarkdown html文件中的文本进行两端对齐。我知道如何在YAML标头后使用<style> body {text-align: justify} </style>(按照this的答案):

---
output: html_document
---

<style> body {text-align: justify} </style> <!-- Justify text. -->

# Text that is justified on both sides

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. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML,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. 

但是,我想找到一种直接在YAML标头中指定此方法的方法,而不是在YAML标头后指定方法,而不必求助于同一存储库中的其他.css文件。换句话说,我不想将一小段html代码放在单独的.css文件中并通过

调用
output:
  html_document:
    css: justify.css

,我不希望它出现在Rmarkdown文件的主体中。我该怎么办?

dongdong28098 回答:在YAML标头中的Rmarkdown html输出中对齐文本

使用普通的pandoc,可以使用include-headers字段。引用pandoc的手册:

  

要包含在文档标题中的原始内容可以使用header-includes指定;但是,使用raw_attribute扩展名将此内容标记为特定输出格式的原始代码很重要,否则它将被解释为markdown。例如:

header-includes:
  - |
    ```{=latex}
    \let\oldsection\section
    \renewcommand{\section}[1]{\clearpage\oldsection{#1}}
    ```

我对this RMarkdown issue的解释是,这在RMarkdown中不起作用。只能包含文件。但是,其中的链接问题之一提供了一种解决方法,其中该文件是通过YAML标头中的R代码段生成的:

---
output:
  html_document:
    includes:
      in_header: header.html
dummy: "`<style>body {text-align: justify; color: green}</style>`{cat,engine.opts=list(file='header.html')}"
---

不太漂亮,但是可以正常工作。

本文链接:https://www.f2er.com/3158873.html

大家都在问