2013-05-07 53 views
18

我在R中使用knitr包和pandoc將.Rmd文件轉換爲PDF。 Pandoc鏈接到一個名爲.bib文件,並自動插入參考書目在PDF 結束我的名爲.bib文件中的條目看起來像這些,從http://johnmacfarlane.net/pandoc/demo/biblio.bib採取:參考書目後的Pandoc插入附錄

@Book{item1, 
     author="John Doe", 
     title="First Book", 
     year="2005", 
     address="Cambridge", 
     publisher="Cambridge University Press" 
    } 

@Article{item2, 
     author="John Doe", 
     title="Article", 
     year="2006", 
     journal="Journal of Generic Studies", 
     volume="6", 
     pages="33-34" 
} 

要建立我的書目,我使用下面的函數,摘自:http://quantifyingmemory.blogspot.co.il/2013/02/reproducible-research-with-r-knitr.html

knitsPDF <- function(name) { 
    library(knitr) 
    knit(paste0(name, ".Rmd"), encoding = "utf-8") 
    system(paste0("pandoc -o ", name, ".pdf ", name, ".md --bibliography /Users/.../Desktop/test.bib --csl /Users/.../Desktop/taylor-and-francis-harvard-x.csl")) 
} 

我.Rmd文件的內容是:

This is some text [@item1] 

This is more text [@item2] 

# References 

並輸出PDF看起來是這樣的:

enter image description here

如果我嘗試插入一個附錄,參考文獻仍然打印在文檔的結尾,就像這樣:

enter image description here

如何插入附件之後的參考?

回答

12

最終引用處理將會改變,以便可以將引用放在任何你喜歡的地方(https://github.com/jgm/pandoc/issues/771),但現在沒有簡單的方法來實現它。

至於建議here,你可以把你的附錄中一個單獨的文件,使用pandoc將其轉換爲一個LaTeX片段,然後包括使用--include-after-body標誌片段。它會在參考書目後出現。

+3

呼高興這是它指定書目的位置。我懷疑儀輝把一個後端加入了編織者,並用它來竊取人們的數據。 – 2013-05-07 21:41:26

+1

但是,正如NOON SILK在您引用的鏈接中所說的,「如果附錄引用了參考文獻,這不起作用。」 :-( – Tripartio 2017-05-18 08:31:16

16

對於較新的版本pandoc,你可以用<div id="refs"></div>source

This is some text [@item1] 

This is more text [@item2] 

# References 

<div id="refs"></div> 

# appendix