R Markdown中的2列部分 [英] 2 column Section in R Markdown

查看:261
本文介绍了R Markdown中的2列部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R Markdown非常新,我在我的工作中为一些新的R用户制作了一个R Markdown HTML页面,为他们介绍并通过一些简单的演示来演示他们。在展示诸如头部尾部之类的东西的时候,它看起来很乱并且很长,因为它会在每个输出之后打印出一个另一个。只要我的.Rmd的其他部分分成两列,我就希望他们。在我的研究中,我遇到了这个问题:






编辑

要更精确地使用列元素,您可以为每组元素使用一个div:

Rmd文件

 < style> 
.column-left {
float:left;
宽度:33%;
text-align:left;
}
.column-center {
display:inline-block;
宽度:33%;
text-align:center;
}
.column-right {
float:right;
宽度:33%;
text-align:right;
}
< / style>

####本部分将有三列

< div class =column-left>
** 1 **一
** 2 **两
< / div>
< div class =column-center>
** 3 **三
** 4 **四
** 5 **五
** 6 **六
< / div>
< div class =column-right>
** 7 ** 7
** 8 ** 8
** 9 ** 9


给我


I'm very new at R Markdown and I'm putting together an R Markdown HTML page for some new R users at my work to give them an intro and walk them through some simple demos. While showing off things like head and tail, it ends up looking messy and long because it prints out each output one after the other. I would like them as long as other sections of my .Rmd to be split into two columns. In my research, I came across this question: 2 Column Report in R Markdown - Render HTML aside Data Frame. There was some discussion of workarounds with HTML code but I'm not at that level in HTML or CSS. I did try including

<div class="columns-2">
</div>

from the official rmarkdown documentation, but it didn't have any effect

As I was ready to give up, there was a comment on the Stack Overflow question by @Molx saying that you can separate columns with ***, but didn't give any further explanation. I tried it out in a few ways: I included the *** in the middle of my R code chunk, I separated my R code chunks and put the *** between the two. When I did the latter, the *** simply became a horizontal rule and did nothing with columns.

I'm hoping to avoid tables and CSS if possible. If anyone has any thoughts on this, I'd appreciate it.

解决方案

rmarkdown file:

#### Put in your css file or directly in rmarkdown

<style>
  .col2 {
    columns: 2 200px;         /* number of columns and width in pixels*/
    -webkit-columns: 2 200px; /* chrome, safari */
    -moz-columns: 2 200px;    /* firefox */
  }
  .col3 {
    columns: 3 100px;
    -webkit-columns: 3 100px;
    -moz-columns: 3 100px;
  }
</style>

#### This section will have three columns

<div class="col3">
**1** one  
**2** two  
**3** three  
**4** four  
**5** five  
**6** six  
**7** seven  
**8** eight  
**9** nine  
</div>

#### This section will have two columns

<div class="col2">
```{r}
head(mtcars)
tail(mtcars)
```
</div>

Gives me this


Edit

To be more precise with the column elements, you can use a div for each set of elements:

Rmd file

<style>
.column-left{
  float: left;
  width: 33%;
  text-align: left;
}
.column-center{
  display: inline-block;
  width: 33%;
  text-align: center;
}
.column-right{
  float: right;
  width: 33%;
  text-align: right;
}
</style>

#### This section will have three columns

<div class="column-left">
**1** one  
**2** two  
</div>
<div class="column-center">
**3** three  
**4** four  
**5** five  
**6** six  
</div>
<div class="column-right">
**7** seven  
**8** eight  
**9** nine  
</div>

Gives me

这篇关于R Markdown中的2列部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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