2017-04-14 147 views
2

我想讓我的YAML頭信息集中在我的html文檔中。如何將我的YAML標題置於R markdown html文檔中?

我希望其他所有東西都保持正常。

我可以將任何html或其他代碼應用到YAML頭以實現此目的嗎?

我該怎麼做?

例子:

我:

--- 
title: "Shiny HTML Doc" 
author: "theforestecologist" 
date: "Apr 14, 2017" 
output: html_document 
runtime: shiny 
--- 
+0

你說所產生的標題/作者/時,它的渲染有關日期?這是應用了任何CSS的產品。 – alistaire

+0

@alistaire是的。我無法弄清楚如何去做。由於這個文本是在YAML中,我假設我不能將正常的HTML或CSS代碼應用到YAML中? – theforestecologist

+0

YAML作爲參數通過'render'傳遞給提供的輸出格式('html_document'),這本身就是一個函數。它全部被渲染爲降價(包括標題/等),pandoc將其轉換爲HTML。如果提供了外部CSS樣式表,它實際上不會在瀏覽器呈現它之前應用。因此,改變標題外觀的最簡單方法就是爲外部樣式表提供特定於要更改的元素的選擇器。 – alistaire

回答

4

下面是一些CSS樣式,你可以用它來完成你所需要的。

  • 降價文檔標題使用h1.title CSS選擇器
  • 降價文檔作者字段使用h4.author CSS選擇器
  • 降價文件datea字段使用h4.date CSS選擇器

這裏是代碼:

--- 
title: "Shiny HTML Doc" 
author: "theforestecologist" 
date: "Apr 14, 2017" 
output: html_document 
runtime: shiny 
--- 

<style type="text/css"> 

h1.title { 
    font-size: 38px; 
    color: DarkRed; 
    text-align: center; 
} 
h4.author { /* Header 4 - and the author and data headers use this too */ 
    font-size: 18px; 
    font-family: "Times New Roman", Times, serif; 
    color: DarkRed; 
    text-align: center; 
} 
h4.date { /* Header 4 - and the author and data headers use this too */ 
    font-size: 18px; 
    font-family: "Times New Roman", Times, serif; 
    color: DarkBlue; 
    text-align: center; 
} 
</style> 


# H1 Header 

Some body text 

## H2 Header 

More body text 



```{r echo=T} 
n <- 100 
df <- data.frame(x=rnorm(n),y=rnorm(n)) 
``` 

這是什麼樣子的,然後結束:

enter image description here

+0

完美!謝謝! :) – theforestecologist

相關問題