2016-01-05 21 views
1

使用knitr使PDF文件,使用fig.align = '中心' 選項時,圖沒有顯示:knitr沒有對齊數字以pdf格式輸出中心?

require(knitr) 
opts_chunk$set(fig.align='center') 

OR

```{r chunkname, fig.align='center'} 
...code that makes figure... 
``` 

無論哪種方式,沒有數字出來的pdf時按下針織PDF按鈕。但是我刪除了fig.align選項,數字出現,左對齊。

這應該已經解決了1.8版本knitr一個老問題,但仍然有同樣的問題:(

任何想法?

謝謝!

+1

你能提供一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)嗎?請注意,全局選項僅適用於在它們被設置的位置(AFAIK)之後的塊*。 –

回答

0

您需要設置。此全局選項 我有這個頭作爲標準配置爲我的文檔,改變它的要求:

### Set global and markdown global options 

```{r global.options, include = TRUE} 
knitr::opts_chunk$set(
    cache  = TRUE,  # if TRUE knitr will cache the results to reuse in future knits 
    fig.width = 10,  # the width for plots created by code chunk 
    fig.height = 10,  # the height for plots created by code chunk 
    fig.align = 'center', # how to align graphics in the final doc. 'left', 'right', 'center' 
    fig.path = 'figs/', # file path to the directory where knitr shall store the graphics files 
    results  = 'asis', # knitr will pass through results without reformatting them 
    echo  = TRUE,  # in FALSE knitr will not display code in the code chunk above it's results 
    message  = TRUE,  # if FALSE knitr will not display any messages generated by code 
    strip.white = TRUE,  # if FALSE knitr will not remove white spaces at the beg or end of code chunk 
    warning  = FALSE) # if FALSE knitr will not display any warning messages in the final document 
``` 

另外,請檢查您在文檔開頭設置了輸出類型:

--- 
title: "blah-blah" 
author: "Denis Rasulev" 
date: "November 2015" 
output: pdf_document 
--- 
+0

'knitr :: opts_chunk $ set()'不比'opts_chunk $ set()'更「全球化」。 –

1

問題解決了! 這不是一個相當「容易」的問題,可能是由於laTex規則(我無法在laTex中編程,所以我不確定這一點)。 問題在於chuncks標識符。我把一個詞,彼此之間的空間由多個單詞一些標識符:

'''{r #identifier one} #before 
code 
''' 

'''{r #identifier-one} #after 
code 
''' 

字當頭之間蜱解決讓降價來呈現文件作爲pdflatex問題。

無論如何謝謝你!