簡體   English   中英

為什么我不能通過 Sweave + Knitr 使用 fig.cap - Latex

[英]Why can't i use fig.cap - Latex through Sweave + Knitr

我對 Latex 很陌生,我正在嘗試創建帶有圖形標題的圖形。

現在,當我嘗試在塊標題(第二個塊)中添加fig.cap ,出現錯誤

乳膠錯誤:不在外部標准模式

我的代碼

<<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)

}

為什么會發生這種情況,如何解決?

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

如果您需要指定其他 LaTeX 圖形選項,請參閱knitr 塊選項文檔的“繪圖”部分:特別是,如果您想使用位置“h”,請在塊選項中使用fig.pos="h" ,如由

fig.pos : (''; character) \\begin{figure}[fig.pos]使用的圖形位置排列的字符串

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM