【问题标题】:Continuation of Numbered List in SlidifySlidify中编号列表的延续
【发布时间】:2014-07-14 14:01:06
【问题描述】:

如何在slidify 的新幻灯片上继续编号列表?

我的代码如下:

---
title       : Another Introductory R Session
subtitle    : 
author      : Christopher Meaney
job         : Biostatistician, University of Toronto
framework   : io2012        # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js  # {highlight.js, prettify, highlight}
hitheme     : tomorrow      # 
widgets     : [mathjax]            # {mathjax, quiz, bootstrap}
mode        : selfcontained # {standalone, draft}

--- .nobackground 

1. Item 1
2. Item 2
3. Item 3
4. Item 4

--- .nobackground

5. Create the following matrix `mat <- matrix(1:9,ncol=3)`.
  * How many ways can you think of to get the column means of `mat`? 
  * Same idea with row means.

6. In matrix notation the OLS/MLE solution for the regression coeffiicients of a linear regression model can be expressed as:

$$ \hat{\boldsymbol\beta} = (\mathbf{X}^{\rm T}\mathbf{X})^{-1} \mathbf{X}^{\rm T}\mathbf{y} $$

* Using the cars dataset investigate the relationship between distance (response variable) as a function of speed (independent variable).
* Create the vector `y` and the design matrix `X`. Dont forget the leading column vector of 1's. Using all of R's fancy matrix algebra functions estimate the $\hat{\boldsymbol\beta}$ vector. 
  * Compare your matrix algebra approach with the following code: `lm(dist~speed,data=cars)`

我希望第二张幻灯片上的列表以 5 开头。第 5 项。6。第 6 项……依此类推。但是列表编号被重置为 1. Item 5. 2. Item 6 等等。

【问题讨论】:

    标签: r r-markdown slidify


    【解决方案1】:

    可能最简单的方法是在幻灯片内容之后添加一些javascript:

    --- .nobackground #foo
    
    5. Create the following matrix `mat <- matrix(1:9,ncol=3)`.
      * How many ways can you think of to get the column means of `mat`? 
      * Same idea with row means.
    
    6. In matrix notation the OLS/MLE solution for the regression coeffiicients of a linear regression model can be expressed as:
    
    $$ \hat{\boldsymbol\beta} = (\mathbf{X}^{\rm T}\mathbf{X})^{-1} \mathbf{X}^{\rm T}\mathbf{y} $$
    
    * Using the cars dataset investigate the relationship between distance (response variable) as a function of speed (independent variable).
    * Create the vector `y` and the design matrix `X`. Dont forget the leading column vector of 1's. Using all of R's fancy matrix algebra functions estimate the $\hat{\boldsymbol\beta}$ vector. 
    * Compare your matrix algebra approach with the following code: `lm(dist~speed,data=cars)`
    
    
    <script>
    $("#foo ol").attr('start', 5)
    </script>
    
    ---
    

    其他方法:

    你可以只使用html

    ---
    <ol start="5">
        <li>Item 5</li>
        <li>Item 6</li>
    </ol>
    ---
    

    或者你可以求助于 CSS:

    --- .nobackground #foo
    
    5. Create the following matrix `mat <- matrix(1:9,ncol=3)`.
      * How many ways can you think of to get the column means of `mat`? 
      * Same idea with row means.
    
    6. In matrix notation the OLS/MLE solution for the regression coeffiicients of a linear regression model can be expressed as:
    
    $$ \hat{\boldsymbol\beta} = (\mathbf{X}^{\rm T}\mathbf{X})^{-1} \mathbf{X}^{\rm T}\mathbf{y} $$
    
    * Using the cars dataset investigate the relationship between distance (response variable) as a function of speed (independent variable).
    * Create the vector `y` and the design matrix `X`. Dont forget the leading column vector of 1's. Using all of R's fancy matrix algebra functions estimate the $\hat{\boldsymbol\beta}$ vector. 
    * Compare your matrix algebra approach with the following code: `lm(dist~speed,data=cars)`
    
    ---
    

    现在在你的 assets/css 中添加一个 styles.css

    #foo OL {
      counter-reset: item 4;
    }
    #foo OL>LI { display: block }
    #foo OL>LI:before {
            content: counter(item) ". ";
            counter-increment: item;
            display:block;
            }
    

    或者,您可以将样式作为 HTML 插入幻灯片中

    <style>
    #foo OL {
      counter-reset: item 4;
    }
    #foo OL>LI { display: block }
    #foo OL>LI:before {
          content: counter(item) ". ";
            counter-increment: item;
            display:block;
            }
    </style>
    

    【讨论】:

    • 这完全有效。谢谢。但是,它会丢弃幻灯片中所有其他元素的所有格式(语法高亮、其他项目符号类型的格式/位置等)。我将更新我的问题以反映实际的第二张幻灯片。希望解决方案可以尽可能地保持格式。
    • 一个快速的解决方法是忽略编号,直到您制作完最终幻灯片,然后手动将 &lt;ol start="5"&gt; 添加到 slidify 生成的 HTML。
    • 这是个好主意。有趣的是,当您在它们之间放置一大块 R 代码时(在同一张幻灯片上),有序列表似乎会中断。你的解决方案也可以在那里工作。
    • javascript 方法对我来说效果很好。谢谢。
    • 当您想在同一张幻灯片中重新开始编号列表时,HTML 方法很不错。就像你有&lt;ol start="number"&gt; 代码&lt;/ol&gt; 一样。然后是 R 代码块{r} R code 然后是另一个有序列表
        。感谢您提供这么多好的解决方案。
      猜你喜欢
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2015-06-12
      • 2015-08-10
      相关资源
      最近更新 更多