【问题标题】:Slidify: Alignment of CodesSlidify:代码对齐
【发布时间】:2013-09-26 18:52:30
【问题描述】:

我对两列幻灯片中的代码对齐有疑问。

这是我的这张幻灯片的代码,

--- &twocol

## Sample R Codes

*** =left

```{r, echo=FALSE}
options(width=30)
```


```{r, fig.height=5.5,highlight=TRUE, fig.show='hide',tidy=TRUE}
mvreg.sim <- function(xcov,beta1=matrix(c(0.7, 0.2, 0.2, 0.7), 
             nr = 2, nc = 2),  err.mu=c(0,0), 
             err.sigma=matrix(c(100,0,0,100), nr=2)){
  library(mvtnorm)
  N <- nrow(xcov)
  e <- rmvnorm(N, mean = err.mu, sigma = err.sigma)  
  y <- matrix(NA, nrow = N, ncol = 2)
  for(i in 1:N){
    y[i,] <- (xcov[i,])%*%beta1 + e[i,]
  }
  return(y)
}
```

*** =right

This is the explanation of the plot.

```{r, fig.height=5.5,highlight=TRUE,echo=FALSE}
x <- seq(0,10, by = 0.01)
y <- x
plot(x, sin(y), xlab = 'x-axis', ylab = 'sin(x)', main = 'Sample Plot')
```

我是新来的,对 html 知之甚少。我使用tidy=TRUEoptions(width=60) 来控制框内代码的宽度,但对齐方式会受到影响。我希望对齐设置为右对齐。非常感谢任何帮助。

【问题讨论】:

    标签: r slidify


    【解决方案1】:

    问题是因为 Slidify 中心默认的两列布局对齐左列(我将在下一个版本中修复它)。这是使用的两列模板。

    ---
    layout: slide
    ---
    {{{ slide.content }}}
    <div style='float:left;width:48%;' class='centered'>
      {{{ slide.left.html }}}
    </div>
    <div style='float:right;width:48%;'>
      {{{ slide.right.html }}}
    </div>
    

    最简单的解决方法是将上述布局保存为twocol.html 在目录assets/layouts 中,然后删除class = "centered"。自定义布局会自动覆盖系统布局。只需确保将文件放入 assets/layouts,因为这是 Slidify 查找自定义布局的位置。

    【讨论】:

    • 有没有继承布局的机制?
    • 是的。虽然是一个非常简单的机制。例如,twocol 布局继承自幻灯片布局,只是将 {{{ slide.content }}} 替换为来自子级的内容。扩展此机制以进行任意替换很容易,但我还没有找到一个好的用例来支持这一点。
    猜你喜欢
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2011-12-28
    • 2018-05-09
    • 1970-01-01
    相关资源
    最近更新 更多