如何修复 Rmarkdown/ioslides 演示文稿中的分栏符 [英] How can I fix column breaks in an Rmarkdown / ioslides presentation

查看:109
本文介绍了如何修复 Rmarkdown/ioslides 演示文稿中的分栏符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

此格式的 rmarkdown 文档 描述了如何执行两列幻灯片,并带有警告:

<块引用>

请注意,内容将跨列流动,因此如果您希望在一侧显示图像而在另一侧显示文本,则应确保图像具有足够的高度以将文本强制移动到幻灯片的另一侧.

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

---书名:《两列》作者:Stack Overflow 上的某个人"日期:2014 年 4 月 4 日,星期五"输出: ioslides_presentation---## 两列尝试 {.smaller}<div class="columns-2">基本图形可以很快...```{r, fig.width = 3, fig.height = 4}par_opts <- 名称(par())历史(nchar(par_opts),中断 = seq(1.5, 9.5, by = 1))``但是 `ggplot2` 也可以很快:```{r, fig.width = 2.5, fig.height = 2.5}需要(ggplot2,安静地= T)qplot(因子(nchar(par_opts)))``

## 两列尝试:Taller Hist {.smaller}<div class="columns-2">基本图形可以很快...```{r, fig.width = 3, fig.height = 6}par_opts <- 名称(par())历史(nchar(par_opts),中断 = seq(1.5, 9.5, by = 1))``但是 `ggplot2` 也可以很快:```{r, fig.width = 2.5, fig.height = 2.5}需要(ggplot2,安静地= T)qplot(因子(nchar(par_opts)))``

## 两列尝试:额外的 div {.smaller}<div class="columns-2">基本图形可以很快...```{r, fig.width = 3, fig.height = 4}par_opts <- 名称(par())历史(nchar(par_opts),中断 = seq(1.5, 9.5, by = 1))``<div>...

但是 `ggplot2` 也可以很快:```{r, fig.width = 2.5, fig.height = 2.5}需要(ggplot2,安静地= T)qplot(因子(nchar(par_opts)))``

这是第四张幻灯片的图片,您可以看到左栏底部的文字被截断,而右栏有足够的空间.

解决方案

我也一直在摸索这个问题.

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

对于图像,我默认在 yaml 中使用 fig_heightfig_width 设置了一个相对较大的尺寸.然后,在块中使用 out.width 属性我控制输出的大小(350px 在这个布局中似乎工作得很好)

---书名:《两列》作者:Stack Overflow 上的某个人"日期:2014 年 4 月 4 日,星期五"输出:ioslides_presentation:fig_height: 7fig_width: 7---## 两列尝试 {.smaller .columns-2}基本图形可以很快...```{r, out.width = '350px'}par_opts <- 名称(par())历史(nchar(par_opts),中断 = seq(1.5, 9.5, by = 1))``但是 `ggplot2` 也可以很快:```{r, out.width = '350px'}需要(ggplot2,安静地= T)qplot(因子(nchar(par_opts)))``

Using what is currently the development version of RStudio (0.98.758), I'm loving that I can author an ioslides presentation in rmarkdown.

The rmarkdown docs for this format give a description of how to do a two-column slide, and it comes with the warning that:

Note that content will flow across the columns so if you want to have an image on one side and text on the other you should make sure that the image has sufficient height to force the text to the other side of the slide.

But I can't seem to possibly make an image big enough! Text still gets pushed off the bottom of the first column. In the presentation below, I'd like to compare a base histogram with a qplot histogram side-by-side in columns, with a few comments and code. I've included code for a relatively short example with some basic solution attempts. If you'll knit it, I think the problem will be obvious. (Note that you will need a 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>

Here's an image of the 4th slide, you can see text is cut off at the bottom of the left column, while the right column has plenty of space.

解决方案

I've been scratching my head around this also.

You can avoid using the divs and use {.columns-2} as a header attribute.

For the images I set a relatively large size by default in the yaml using fig_height and fig_width. Then, using the out.width attribute in the chunk I control the size of the output (350px seems to work well in this layout)

---
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)))
```

这篇关于如何修复 Rmarkdown/ioslides 演示文稿中的分栏符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆