Rmarkdown font size and header

前端 未结 1 1129
太阳男子
太阳男子 2020-12-12 21:13

I recently opened a standard Rmd file without editing anything. The default file looks like this:

Untitled.rmd

---
title: \"myfile\"         


        
相关标签:
1条回答
  • 2020-12-12 21:45

    This is what I used to control font size and color in an R-markdown file. It basically overrides the CSS style sheets without having to create a new file. The example changes the sizes of the headers and titles, as well as the inline text and the R-code text, and sets some colors as well.

    In my case I needed to pack more information into a document that had a specified number of pages so I made everything smaller.

    ---
    title: "This is a title"
    date: 25 May 2015
    output:
    html_document:
    theme: cerulean
    ---
    
    <style type="text/css">
    
    body{ /* Normal  */
          font-size: 12px;
      }
    td {  /* Table  */
      font-size: 8px;
    }
    h1.title {
      font-size: 38px;
      color: DarkRed;
    }
    h1 { /* Header 1 */
      font-size: 28px;
      color: DarkBlue;
    }
    h2 { /* Header 2 */
        font-size: 22px;
      color: DarkBlue;
    }
    h3 { /* Header 3 */
      font-size: 18px;
      font-family: "Times New Roman", Times, serif;
      color: DarkBlue;
    }
    code.r{ /* Code block */
        font-size: 12px;
    }
    pre { /* Code block - determines code spacing between lines */
        font-size: 14px;
    }
    </style>
    
    
    # H1 Header
    
    Some body text
    
    ## H2 Header
    
    More body text
    
    ### H3 Header
    
    blah blah blah
    
    ```{r echo=T}
    n <- 100
    df <- data.frame(x=rnorm(n),y=rnorm(n))
    ```
    
    ### Another H3
    

    Update:

    Added more more styles, comments, and a bit of color to make this answer more useful. And a screen shot:

    0 讨论(0)
提交回复
热议问题