如何在Rmarkdown / ioslides演示文稿中修复列分隔符

时间:2014-04-04 19:35:05

标签: r rstudio r-markdown

使用目前RStudio(0.98.758)的开发版本,我很高兴我可以在ioslides中撰写rmarkdown演示文稿。

rmarkdown docs for this format说明了如何进行双栏幻灯片,并附带警告:

  

请注意,内容将在列中流动,因此,如果您想要在一侧显示图像而在另一侧显示文本,则应确保图像具有足够的高度以将文本强制到幻灯片的另一侧。 / p>

但我似乎无法使图像足够大!文本仍然被推离第一列的底部。在下面的演示文稿中,我想在列中并排比较基本直方图和qplot直方图,并附上一些注释和代码。我已经为一些相对简短的示例包含了一些基本的解决方案尝试的代码。如果你要编织它,我认为这个问题很明显。 (请注意,您需要preview version of RStudio。)

---
title: "Two Column"
author: "Some guy on Stack Overflow"
date: "Friday, April 04, 2014"
output: ioslides_presentation
---

## Two-Column Attempt {.smaller}

<div class="columns-2">
Base graphics can be quick...

```{r, fig.width = 3, fig.height = 4}
par_opts <- names(par())
    hist(nchar(par_opts),
         breaks = seq(1.5, 9.5, by = 1))
```

But `ggplot2` can be quick too:

```{r, fig.width = 2.5, fig.height = 2.5}
require(ggplot2, quietly = T)
qplot(factor(nchar(par_opts)))
```
</div>

## Two-Column Attempt: Taller Hist {.smaller}

<div class="columns-2">
Base graphics can be quick...

```{r, fig.width = 3, fig.height = 6}
par_opts <- names(par())
    hist(nchar(par_opts),
         breaks = seq(1.5, 9.5, by = 1))
```

But `ggplot2` can be quick too:

```{r, fig.width = 2.5, fig.height = 2.5}
require(ggplot2, quietly = T)
qplot(factor(nchar(par_opts)))
```
</div>

## Two-Column Attempt: Extra div {.smaller}

<div class="columns-2">

Base graphics can be quick...

```{r, fig.width = 3, fig.height = 4}
par_opts <- names(par())
    hist(nchar(par_opts),
         breaks = seq(1.5, 9.5, by = 1))
```

<div>
...
</div>

But `ggplot2` can be quick too:

```{r, fig.width = 2.5, fig.height = 2.5}
require(ggplot2, quietly = T)
qplot(factor(nchar(par_opts)))
```
</div>

这是第4张幻灯片的图片,你可以看到左栏底部的文字已被切断,而右栏有足够的空间。

cut off

1 个答案:

答案 0 :(得分:16)

我也一直在摸不着头脑。

您可以避免使用div并使用{.columns-2}作为 标题属性。

对于图像,我默认使用fig_heightfig_width在yaml中设置了相对较大的尺寸。 然后,使用块中的out.width属性来控制输出的大小(350px似乎在此布局中运行良好)

---
title: "Two Column"
author: "Some guy on Stack Overflow"
date: "Friday, April 04, 2014"
output:
  ioslides_presentation:
    fig_height: 7
    fig_width: 7
---

## Two-Column Attempt {.smaller .columns-2}

Base graphics can be quick...

```{r, out.width =  '350px'}
par_opts <- names(par())
    hist(nchar(par_opts),
         breaks = seq(1.5, 9.5, by = 1))
```


But `ggplot2` can be quick too:

```{r, out.width =  '350px'}
require(ggplot2, quietly = T)
qplot(factor(nchar(par_opts)))
```
相关问题