r语言 - 为什么我不能使用 fig.cap - 乳胶通过编织 + 针织



我是Latex的新手,我正在尝试用我的方式创建一个带有数字标题的图形。

现在,当我尝试添加fig.cap在块标题(第二个块)我得到错误

Latex错误: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)
}

为什么会发生这种情况,如何解决?

您应该从Sweave文件中省略begin{figure}(未在MWE中显示)和end{figure};当您指定fig.cap时,它们由knitr自动生成(并且在MWE的情况下是冗余的,导致错误)。

如果您需要指定其他LaTeX图形选项,请参阅knitr块选项文档中的"Plot"部分:特别是,如果您想使用位置"h",请在块选项中使用fig.pos="h",如

所示

fig.pos: (";字符)用于begin{figure}[fig.pos]

中图形位置排列的字符串。

最新更新