我正在尝试创建一个块挂钩,它可以生成\floatfoot{}
作为块的输出的一部分。
希望以下示例明确说明我要实现的目标:
这是knitr文件。
\documentclass[a4paper]{article}
\title{Learn Moar knitr!}
\author{Foo Bar}
\date{\today}
\usepackage{blindtext}
\usepackage{floatrow}
\begin{document}
\blindtext
<<label=plotWithNotes, fig.lp='fig:', fig.cap='This is a figure'>>=
plot(rnorm(100), rbinom(n = 100, size = 1, prob = 0.5))
@
\end{document}
\begin{figure}[]
\includegraphics[width=\maxwidth]{figure/plotWithNotes} \caption[This is a figure]{This is a figure\label{fig:plotWithNotes}}
\end{figure}
\floatfoot{}
包提供的标记floatrow
会生成图表的脚注,为了显示其用途,我修改了上面的LaTeX块。
\begin{figure}[]
\includegraphics[width=\maxwidth]{figure/plotWithNotes} \caption[This is a figure]{This is a figure\label{fig:plotWithNotes}}
\floatfoot{\emph{Note:} This is a footer to the plot and contains some information about the plot.}
\end{figure}
有没有办法可以使用chunk选项在floatfoot上面生成文本?
我开始编写这样的函数,但无法让它工作:
<<echo = TRUE, include = FALSE>>=
fnOutHookInsertFoot = function(x = NULL, options = NULL) {
# find the location of the \end{figure}
gsub('\\end{figure}', '\\floatfoot{Some text.}\\end{figure}',
x, fixed = TRUE)
}
# fnOutHookInsertFoot()
knit_hooks$set(plot = fnOutHookInsertFoot)
@