knitr/Rmarkdown:图 side-by-side 有一个标题
knitr/Rmarkdown: Figures side-by-side with a single caption
在 .Rmd
文档中有几种生成数字的方法 side-by-side。如果数字已经存在,对我来说最简单的方法是使用knitr::include_graphics(c(fig1, fig2, ...))
[Thx: Yihui!]
但是当我这样做时,我找不到添加整体图形标题的方法,而在 LaTeX 中很容易做到这一点。
这是一个例子:
块
```{r, out.width = "30%", echo=FALSE}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
输出:
如果我在块选项中添加 fig.cap
,我会得到两个单独的图,每个图都有相同的图标题。
```{r, out.width = "30%", echo=FALSE, fig.cap="Left: scatterplot of mathscore data; Right: Data ellipses for the two groups."}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
是否有其他方法可以实现我想要的效果 - 两个 sub-figures side-by-side,具有共同的标题?
针织品或纯乳胶均可。
在 knitr 中将块选项设置为:
echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center'
我使用了 latex 包子标题,
在 YAML header-includes 部分导入 header。
---
title: "Untitled"
author: "V"
date: "22 4 2020"
output: pdf_document
header-includes:
- \usepackage{subcaption}
---
# add Two figures with latex
\begin{figure}[h]
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}
\caption{This is the main caption - Years 2020 - 2030 - the main caption. }
\end{figure}
# add Two figures with Knitr
```{r, echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center', fig.cap="This is the main caption - Years 2020 - 2030 - the main caption."}
knitr::include_graphics(c("CAT.png","CAT.png"))
在 .Rmd
文档中有几种生成数字的方法 side-by-side。如果数字已经存在,对我来说最简单的方法是使用knitr::include_graphics(c(fig1, fig2, ...))
[Thx: Yihui!]
但是当我这样做时,我找不到添加整体图形标题的方法,而在 LaTeX 中很容易做到这一点。 这是一个例子:
块
```{r, out.width = "30%", echo=FALSE}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
输出:
如果我在块选项中添加 fig.cap
,我会得到两个单独的图,每个图都有相同的图标题。
```{r, out.width = "30%", echo=FALSE, fig.cap="Left: scatterplot of mathscore data; Right: Data ellipses for the two groups."}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
是否有其他方法可以实现我想要的效果 - 两个 sub-figures side-by-side,具有共同的标题?
针织品或纯乳胶均可。
在 knitr 中将块选项设置为:
echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center'
我使用了 latex 包子标题,
在 YAML header-includes 部分导入 header。
---
title: "Untitled"
author: "V"
date: "22 4 2020"
output: pdf_document
header-includes:
- \usepackage{subcaption}
---
# add Two figures with latex
\begin{figure}[h]
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}
\caption{This is the main caption - Years 2020 - 2030 - the main caption. }
\end{figure}
# add Two figures with Knitr
```{r, echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center', fig.cap="This is the main caption - Years 2020 - 2030 - the main caption."}
knitr::include_graphics(c("CAT.png","CAT.png"))