2015-09-19 29 views
2

我對乳膠很陌生,我正在試圖用數字標題創建圖形。爲什麼我不能使用fig.cap - Latex通過Sweave + Knitr

現在,當我嘗試把塊加入fig.cap標題(第二塊),我得到的錯誤

Latex error: Not in outer par mode

我的代碼

<<echo = FALSE>>= 
source("analysis.R") 

repoData <- readRDS("data/repoData.rds") 

    a4width<- 8.3 
    a4height<- 11.7 
@ 
\begin{figure}[h] 
<<echo = FALSE, fig.width= a4width, fig.height=0.35*a4height>>= 
G2(repoData) 
@ 
\end{figure} 


## ---- G2 ---- 
G2 <- function(df) { 
    # For inflation graph 
    plot <- ggplot(df, aes(x = Month, y = Percent)) + 

    geom_line(colour = "firebrick") + 
    xlab("") + 
    ylab("Repo rate") + 
    theme_classic() + 
    theme(axis.title.y = element_text(vjust = 1)) 

    return(plot) 

} 

爲什麼會出現這種情況,這可怎麼解決?

回答

2

您應該從Sweave文件中省略\begin{figure}(未在您的MWE中顯​​示)和\end{figure};當您指定fig.cap時,它們將自動生成knitr(並且在MWE情況下會冗餘地導致錯誤)。

如果需要指定其他LaTeX的人物選擇,看到knitr chunk options documentation的「暗算」一節中,尤其是如果你想使用位置「H」,用你的大塊選項fig.pos="h",通過

指示

fig.pos : (''; character) a character string for the figure position arrangement to be used in \begin{figure}[fig.pos]

+0

啊。但是,我怎麼能指定數字放在哪裏呢?因爲我需要\ {figure}之後的[h](「here」)。 – uncool