编织的子图或子标题? [英] Subfigures or Subcaptions with knitr?

查看:114
本文介绍了编织的子图或子标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用knitr生成子图(带有相关的子标题)?这是一个最小的工作示例:

Is it possible to produce subfigures (with associated subcaptions) using knitr? Here is a minimal working example:

\documentclass{article}

\begin{document}

<<echo = FALSE, fig.cap = c("Some numbers.", "Some more numbers."), out.width = "0.5\\textwidth", fig.align = "center">>=

plot(1:10)
plot(30:100)

@

\end{document}

这将导致两个图分别标记为图1和图2,并带有标题.但是我希望将它们分别标记为图1a"和图1b",就像使用副标题LaTeX软件包一样.

This results in two figures labelled Figure 1 and Figure 2 with captions as defined (respectively). But I want them to be labelled "Figure 1a" and "Figure 1b", as you can do with the subcaption LaTeX package.

我知道有一个编织选项"fig.env",但这不能解决(至少不使用例如"fig.env ='subfigure'").关于Sweave,这里也有类似的帖子,但是解决方案是不雅致的破解:

I know there is a knitr options "fig.env", but this doesn't solve it (at least not using, for example, "fig.env = 'subfigure'"). There is a similar post here regarding Sweave, but the solution is an inelegant hack: http://texblog.org/2011/12/01/sweave-subfig-controlling-figure-size-and-placement/

推荐答案

knitr(> = v1.5)支持

knitr (>= v1.5) supports subfigures. You can use the chunk option fig.subcap. Here is a minimal example.

\documentclass{article}
\usepackage{subfig}
\begin{document}

<<fig-sub, fig.cap='two plots', fig.subcap=c('one plot', 'the other one'), out.width='.49\\linewidth'>>=
plot(1:10)
plot(rnorm(10), pch=19)
@

\end{document}

这篇关于编织的子图或子标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆