6

Let's say I want to create this numbered list:

  1. Sed ut perspiciatis unde omnis iste natus error...
  2. Nemo enim ipsam voluptatem quia voluptas sit...
  3. Neque porro quisquam est, qui dolorem ipsum quia...
  4. Quis autem vel eum iure reprehenderit qui in ea voluptate...

In R Markdown, the documentation suggests that to continue such a list after an interruption, one should prepend each list item with (@) as follows:

(@) Sed ut perspiciatis unde omnis iste natus error...
(@) Nemo enim ipsam voluptatem quia voluptas sit...

 This is an interrupting block of text...

(@) Neque porro quisquam est, qui dolorem ipsum quia..
(@) Quis autem vel eum iure reprehenderit qui in ea voluptate...

and this will continue the numbering after the interruption.

However, I tried, without success, to use this approach in continuing a numbered list in an ioslides presentation generated from R Markdown i.e.

(@) Nemo enim ipsam voluptatem quia voluptas sit...

 ***

(@) Neque porro quisquam est, qui dolorem ipsum quia..

where *** represents the slide break.

Is there a way I can achieve number continuation across the slide break?

BroVic
  • 979
  • 9
  • 26

2 Answers2

7

You can use the HTML <ol> tag (ol is for ordered list) which has an optional start argument.

Here is minimal example:

---
title: "Untitled"
output: ioslides_presentation
---

## Slide

<ol>
<li> Sed ut perspiciatis unde omnis iste natus error...
<li> Nemo enim ipsam voluptatem quia voluptas sit...
</ol>

This is an interrupting block of text...

<ol start=3>
<li> Neque porro quisquam est, qui dolorem ipsum quia..
<li> Quis autem vel eum iure reprehenderit qui in ea voluptate...
</ol>

enter image description here

This also works across slides.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Thanks, worked perfectly. But more importantly, I learnt something I never knew - that I could use HTML tags right inside R Markdown. This new knowledge will make a HUGE difference going forward. Cheers! – BroVic Aug 23 '18 at 20:20
  • Note that with a bit more html (e.g., in a .css), you can set up styles to [continue the numbering automatically](https://stackoverflow.com/questions/30927354/continue-ordered-list-numbering-automatically) – wes Jun 16 '22 at 07:28
2

The accepted answer works ok if you only have a few items, but if you are dealing with many listed items and the number may change (i.e. you add or subtract some), the <ol start=3> approach becomes tedious.

Additionally, the link in the comment of the accepted answer (Continue ordered list numbering automatically) did not work across slides for me using xaringan.

As a workaround, you can create a counter using embedded R code so that you don't have to manually reference the item number. I tested this with xaringan but not ioslides.

---
title: "Presentation Ninja"
subtitle: "with xaringan"
author: "Yihui Xie"
date: "2016/12/12"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      countIncrementalSlides: false
---

## Slide

<ol>
<li> Sed ut perspiciatis unde omnis iste natus error... `r q<-1`
<li> Nemo enim ipsam voluptatem quia voluptas sit... `r q<-q+1`
</ol>

This is an interrupting block of text...

---

And a new slide....

<ol start=`q+1`>
<li> Neque porro quisquam est, qui dolorem ipsum quia.. `r q<-q+1`
<li> Quis autem vel eum iure reprehenderit qui in ea voluptate...`r q<-q+1`
</ol>

The r q<-q+1 blocks are not necessary in the last few items. If I'm going to be doing this a lot, I simply store the ol tag and the increment block into a register in Emacs so they can be called upon quickly.

haff
  • 918
  • 2
  • 9
  • 20