【问题标题】:How to keep default R markdown colors when knitting to html?编织到html时如何保持默认的R markdown颜色?
【发布时间】:2021-12-29 15:37:12
【问题描述】:

在 R markdown 或 R studio 中,对于这样的一行

library('tidyverse')

library 为蓝色,tidyverse 为绿色。当我编织到 html 时,它们分别显示为深红色和红色。如何编织我的 html 以保持整个文档的原始颜色?在R Markdown Cookbook 中,它说我可以使用span tag 并设置颜色,但这似乎适用于特定的代码块。我发现this post 是背景颜色,而不是文本。或this one,但又是单个代码块。我相信这是因为颜色在 R 和 HTML 中有不同的名称?有没有办法在 YAML 标头下方的 <style type="text/css"> 部分中指定它?我用 R 编写代码,但我对 CSS 或 HTML 完全陌生。

【问题讨论】:

    标签: html r r-markdown


    【解决方案1】:

    在 YAML 标头中使用 highlight: textmate

    例如,

    ---
    title: "Test"
    output: 
      html_document:
        highlight: textmate
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## Test
    
    ```{r}
    library("tidyverse")
    ```
    

    编织到

    进一步阅读

    R Markdown: The Definitive Guide

    【讨论】:

    • 谢谢,效果很好!也感谢您的阅读参考。
    猜你喜欢
    • 2021-08-14
    • 2018-05-26
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    相关资源
    最近更新 更多