[英]two-column layouts in RStudio presentations/slidify/pandoc
I'm trying to come up with a good system for generating slides and accompanying handouts. 我正在努力想出一个很好的系统来生成幻灯片和随附的讲义。 The ideal system would have the following properties:
理想的系统具有以下属性:
pandoc
slide separator format (automatically generate a new slide after headers of a specified level) is preferred pandoc
幻灯片分隔符格式(在指定级别的标题之后自动生成新幻灯片)是首选 sed
), but would prefer not to write a huge infrastructure sed
),但不想写一个庞大的基础设施 Here's what I've discovered so far about the various options: 以下是我迄今为止发现的各种选项:
pandoc
slide separator format, although there is a workaround pandoc
幻灯片分隔符格式,虽然有一种解决方法 psnup
...) psnup
这样的东西......) RStudio
presentations ( .Rpres
files): RStudio
演示文稿( .Rpres
文件):
pandoc
slide separator format pandoc
幻灯片分隔符格式 rmarkdown
. rmarkdown
第2版捆绑在一起。 It addresses many of the above issues with the .Rpres
format. .Rpres
格式解决了上述许多问题。 pandoc
: may be the only markdown-translator that has features such as footnotes, bibliography support, etc.. I can also use pandoc
to generate LaTeX using the tufte-handout class , which meets my criteria of beauty. pandoc
:可能是唯一具有脚注,参考书目支持等功能的降价转换器。我也可以使用pandoc
来生成使用tufte-handout类的 LaTeX,这符合我的美容标准。
pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html
, but it doesn't seem to be ... pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html
,但它似乎不是...... Rnw
(knitr-dialect Sweave) rather than R markdown to begin with. Rnw
(knitr-dialect Sweave)而不是R markdown开始。 This would give me ultimate flexibility ... After all that, my specific question is: what's the best (easiest) way to generate a two-column layout for HTML output ? 毕竟,我的具体问题是: 为HTML输出生成两列布局的最佳(最简单)方法是什么 ?
Any other advice will also be appreciated. 任何其他建议也将不胜感激。
This is an old Q, but I was recently plagued by a similar question, here's what I found: 这是一个古老的Q,但最近我被一个类似的问题困扰,这是我发现的:
Using the RPres format, two columns can be specified like so ( details ). 使用RPres格式,可以像这样指定两列( 详细信息 )。 Note that RPres can only be converted to HTML by clicking a button in RStudio, there doesn't seem to be any command line method, which is a bit annoying.
请注意,RPres只能通过单击RStudio中的按钮转换为HTML,似乎没有任何命令行方法,这有点烦人。 Despite, that I'd say it is currently the simplest and most flexible method for getting slide columns with markdown:
尽管如此,我认为它是目前使用markdown获取幻灯片列的最简单,最灵活的方法:
===
Two Column Layout
===
This slide has two columns
***
```{r, echo=FALSE}
plot(cars)
```
Some flexibility is afforded by adjusting the column proportions: 通过调整色谱柱比例可以提供一些灵活性:
===
Two Column Layout
===
left: 30%
This slide has two columns
***
```{r, echo=FALSE}
plot(cars)
```
With rmarkdown we can get two columns, but with no control over where the break is, which is a bit of a problem: 使用rmarkdown我们可以获得两列,但无法控制中断的位置,这有点问题:
---
output: ioslides_presentation
---
## Two Column Layout {.columns-2}
This slide has two columns
```{r, echo=FALSE}
plot(cars)
```
We can also mix markdown and LaTeX in an Rmd file using the beamer_presentation
format in RStudio to get two columns like this, but can't run any code in either column, which is a limitation: 我们还可以使用RStudio中的
beamer_presentation
格式在一个Rmd文件中混合markdown和LaTeX来获得这样的两列,但不能在任一列中运行任何代码,这是一个限制:
---
output: beamer_presentation
---
Two Column Layout
-------
\begin{columns}
\begin{column}{0.48\textwidth}
This slide has two columns
\end{column}
\begin{column}{0.48\textwidth}
If I put any code in here I get an error, see
https://support.rstudio.com/hc/communities/public/questions/202717656-Can-we-have-columns-in-rmarkdown-beamer-presentations-
\end{column}
\end{columns}
Seems like a regular Rnw LaTeX doc is the best way to get columns if you want to use LaTex, not this markdown hybrid (cf. two column beamer/sweave slide with grid graphic ) 看起来像常规的Rnw LaTeX doc是获取列的最佳方式,如果你想使用LaTex,而不是这个降价混合(参见两列beamer / sweave slide with grid graphic )
In all of the above an image can be placed in an column. 在上述所有情况中,图像可以放在一列中。
The slidify website has instructions on making two columns here: http://slidify.org/customize.html but it's not clear what has to go into the assets/layouts folder to make it work slidify网站有关于在这里列出两列的说明: http ://slidify.org/customize.html但是不清楚要进入assets / layouts文件夹以使其工作
I now have what I think is a reasonable solution that should apply at least to ioslides
-based solutions, and maybe (?) to other HTML5-based formats. 我现在拥有的是一个合理的解决方案,至少应该适用于基于
ioslides
的解决方案,也许(?)适用于其他基于HTML5的格式。 Starting here , I added 从这里开始,我补充道
<style>
div#before-column p.forceBreak {
break-before: column;
}
div#after-column p.forceBreak {
break-after: column;
}
</style>
to the beginning of my document; 到我的文件的开头; then putting
<p class="forceBreak"></p>
within a slide with {.columns-2}
breaks the column at that point, eg 然后在
{.columns-2}
的幻灯片中放置<p class="forceBreak"></p>
在该点打破列,例如
## Latin hypercube sampling {.columns-2}
- sample evenly, randomly across (potentially many) uncertain parameters
<p class="forceBreak"></p>
![](LHScrop.png)
[User:Saittam, Wikipedia](https://commons.wikimedia.org/wiki/File:LHSsampling.png#/media/File:LHSsampling.png)
There may be an even better way, but this isn't too painful. 可能有更好的方法,但这不是太痛苦。
@ChrisMerkord points out in comments that @ChrisMerkord在评论中指出
.forceBreak { -webkit-column-break-after: always; break-after: column; }
worked instead (I haven't tested ...) 工作(我还没有测试......)
I got an idea from HERE , the basic solutions was: 我从这里得到了一个想法,基本的解决方案是:
### Function *inner_join*
. . .
`<div style="float: left; width: 50%;">`
``` {r, echo = FALSE, results = 'markup', eval = TRUE}
kable(cbind(A,B))
```
`</div>`
`<div style="float: right; width: 50%;">`
```{r, echo = TRUE, results = 'markup', eval = TRUE}
inner_join(A,B, by="C")
```
`</div>`
There is a workaround for beamer error. 有关投影仪错误的解决方法 。
In short: Error is related to pandoc conversion engine, which treats everything between \\begin{...}
and \\end{...}
as TeX . 简而言之:错误与pandoc转换引擎有关,它将
\\begin{...}
和\\end{...}
视为TeX 。 It can be avoided by giving new definition for begin{column}
and end{column}
in yaml header. 通过为yaml标头中的
begin{column}
和end{column}
提供新定义,可以避免这种情况。
Create mystyle.tex and write there: 创建mystyle.tex并在那里写:
\def\begincols{\begin{columns}}
\def\begincol{\begin{column}}
\def\endcol{\end{column}}
\def\endcols{\end{columns}}
In the Rmd file use these new definitions
在Rmd文件中使用这些新定义
---
output:
beamer_presentation:
includes:
in_header: mystyle.tex
---
Two Column Layout
-------
\begincols
\begincol{.48\textwidth}
This slide has two columns.
\endcol
\begincol{.48\textwidth}
```{r}
#No error here i can run any r code
plot(cars)
```
\endcol
\endcols
So far I haven't been able to do better than hacking my own little bit of markup on top of the rmd
format: I call my source file rmd0
and run a script including this sed
tidbit to translate it to rmd
before calling knit
: 到目前为止,我还没有能够做的比黑客的标记我自己的一点在上面更好的
rmd
格式:我打电话给我的源文件rmd0
并运行,包括这样的脚本sed
珍闻要翻译成rmd
之前调用knit
:
sed -e 's/BEGIN2COLS\(.*\)/<table><tr><td style="vertical-align:top; width=50%" \1>/' \
-e 's/SWITCH2COLS/<\/td><td style="vertical-align:top">/' \
-e 's/END2COLS/<\/td><\/tr><\/table>/' ...
There are a few reasons I don't like this. 有几个原因我不喜欢这个。 (1) It's ugly and special-purpose, and I don't have a particularly good way to allow optional arguments (eg relative widths of columns, alignment, etc.).
(1)它是丑陋和特殊目的,我没有一个特别好的方法来允许可选参数(例如列的相对宽度,对齐等)。 (2) It has to be tweaked for each output format (eg if I wanted LaTeX/beamer output I would need to substitute
\\begin{columns}\\begin{column}{5cm} ... \\end{column}\\begin{column}{5cm} ... \\end{column}\\end{columns}
instead (as it turns out I want to ignore the two-column formatting when I make LaTeX-format handouts, so it's a little easier, but it's still ugly). (2)必须针对每种输出格式进行调整(例如,如果我想要LaTeX / beamer输出,我需要替换
\\begin{columns}\\begin{column}{5cm} ... \\end{column}\\begin{column}{5cm} ... \\end{column}\\end{columns}
(因为事实证明我想在制作LaTeX格式的讲义时忽略两列格式,所以它更容易一点,但它仍然是丑陋)。
Slidify may yet be the answer. Slidify可能是答案。
You can use fenced_divs
notation or :::
to create columns or `Two Content layout'. 您可以使用
fenced_divs
表示法或:::
来创建列或“两个内容布局”。 See also this page to know more about the notation. 另请参阅此页面以了解有关表示法的更多信息。
## Slide With Image Left
::: columns
:::: column
left
::::
:::: column
right
```{r your-chunk-name, echo=FALSE, fig.cap="your-caption-name"}
knitr::include_graphics("your/figure/path/to/the-image.pdf")
#The figure will appear on the right side of the slide...
```
::::
:::
Since pandoc 2+
, which supports the notation, was implemented in RStudio v1.2+
, you may need to install RStudio v1.2+
first. 由于支持符号的
pandoc 2+
是在RStudio v1.2+
,因此您可能需要首先安装RStudio v1.2+
。 The installation is easy enough (at least in my case); 安装很简单(至少在我的情况下); just download and install
RStudio v1.2+
. 只需下载并安装
RStudio v1.2+
。 In the way of installation, the former version of RStudio
on your computer will be replaced with the new one without uninstalling it manually. 在安装过程中,计算机上的旧版
RStudio
将被替换为新版本,而无需手动卸载。
The :::
notation can be used even when you knit .Rmd
files with beamer_presentation
option, as well as when you create HTML slides. 即使您使用
beamer_presentation
选项编织.Rmd
文件,以及创建HTML幻灯片时,也可以使用:::
表示法。 So we don't have to neither mix markdown and LaTeX notation in one file, nor add additional codes any longer: just knit the file as you knit other .Rmd
with other options. 因此,我们不必在一个文件中混合使用markdown和LaTeX表示法,也不必再添加其他代码:只需在编织其他
.Rmd
使用其他选项编织文件。
Not a direct solution, but Yihui's Xaringan
package https://github.com/yihui/xaringan/ works for me. 不是直接的解决方案,但是Yihui的
Xaringan
软件包https://github.com/yihui/xaringan/适合我。 It's based on remark.js
. 它基于
remark.js
。 In the default template, you can use .pull-left[]
and .pull-right[]
. 在默认模板中,您可以使用
.pull-left[]
和.pull-right[]
。 Example: https://slides.yihui.name/xaringan/#15 . 示例: https : //slides.yihui.name/xaringan/#15 。 You only need a minimum tweak on the existing
.rmd
files. 您只需要对现有的
.rmd
文件进行最小调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.