【问题标题】:Change the color of header in Rmarkdown Prettydoc templates更改 Rmarkdown Prettydoc 模板中标题的颜色
【发布时间】:2026-02-15 09:35:01
【问题描述】:

在R Markdown中使用包prettydoc,有模板,代码如下

---
title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
---

输出看起来像这样

想知道我可以在哪里更改超越的颜色,所以也许它可以从红色变为橙色或我声明的任何颜色。此标头的 .css 位于何处?提前谢谢你

【问题讨论】:

    标签: css r r-markdown


    【解决方案1】:

    最简单的方法是覆盖 Bootswatch Cayman 主题 CSS。
    要获取linear-gradient() CSS 函数的默认值,负责“沿直线在两个或多个颜色之间的progressive transition”,您可以“右键单击网页上的元素并选择Inspect Element ”:

    想知道我在哪里可以改变超越的颜色,所以也许它可以从红色变成橙色......

    所以,应用 CSS 线性渐变Syntax:
    background-image: linear-gradient(direction, color-stop1, color-stop2, ...);

    ---
    title: Nineteen Years Later
    author: Harry Potter
    date: July 31, 2016
    output:
      prettydoc::html_pretty:
        theme: cayman
        highlight: github
    ---
    
    ```{css my-header-colors, echo = FALSE}
    .page-header {
        background-image: linear-gradient(120deg, red, orange);
    }
    ```
    

    我们得到输出:

    此标头的 .css 位于何处?

    Github:https://github.com/yixuan/prettydoc/blob/master/inst/resources/css/cayman.css
    Windows(PC):..\R\win-library\4.0\prettydoc\resources\css\cayman.css

    这有什么帮助吗?

    【讨论】:

    • 是的,谢谢。linear-gradient() 是个绝招!