4

I want to insert a table of contents slide toward the beginning , but not the very beginning.

Additionally, I want it so that as each new section arrives, the table of contents slide is repeated, but with this time everything grayed out except the current section, for example see image.

(this other answer will not work because toc: true just puts one table of contents at the very beginning)

Some answers KIND of exist in Latex (see here), but I don't know how to operationalize these within markdown. More generally, I have trouble integrating native beamer latex into rmarkdown, so if someone can show me how to do that, esp with this example, that is helpful.

enter image description here

Beamer preamble:

output:
  beamer_presentation:
    fig_width: 7
    fig_height: 6
    fig_caption: false
#    keep_tex: true
#    toc: true
    slide_level: 3
    includes:
      in_header: ~/Google Drive/.../.../../latexbeamertheme.r
header-includes:
- \AtBeginSection[]{\begin{frame}\tableofcontents[currentsection]\end{frame}}
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90

1 Answers1

4

You can solve this problem via header-includes; that's how you add things to what we'd call the preamble in a LaTeX document. Here's example code that generates a presentation with what I think you want to accomplish:

---
title: "Example"
output: beamer_presentation
header-includes:
- \AtBeginSection[]{\begin{frame}\tableofcontents[currentsection]\end{frame}}
---

# Test Section One

----

Test

----

Test


# Test Section Two

----

Test

----

Test

Edit:

If you want or need to do this manually, rather than using the header-includes approach, you can:

---
title: "Example"
output: beamer_presentation
---

# Test Section One

----

\tableofcontents[currentsection]

----

Test

----

Test


# Test Section Two

----

\tableofcontents[currentsection]

----

Test

----

Test
duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • Now this doesn't seem to work when I add it to my full doc, which already has a latex preamble. Could it be the case it's getting overridden? – wolfsatthedoor Sep 04 '17 at 23:29
  • (See question for my preamble bit for beamer markdown) – wolfsatthedoor Sep 04 '17 at 23:29
  • Is it possible to post/comment your whole code (or at least all the code before the presentation content and code for a couple of slides, or a dummy slide or two)? – duckmayr Sep 04 '17 at 23:32
  • Also, does putting the example code I posted in its own separate document Knit OK for you? – duckmayr Sep 04 '17 at 23:32
  • Do you want me to show you the contents of my latex preamble file? Maybe that is doing it? – wolfsatthedoor Sep 04 '17 at 23:35
  • I would suggest adding the `\AtBeginSection[]{\begin{frame}\tableofcontents[currentsection]\end{frame}}` as a new line in the file you've included via `in_header`; let me know if that works. – duckmayr Sep 04 '17 at 23:36
  • I might be spacing it wrong, but I get this error: Error in yaml::yaml.load(enc2utf8(string), ...) : Reader error: control characters are not allowed: #C at 345 Calls: ... yaml_load_utf8 -> mark_utf8 -> -> .Call Execution halted – wolfsatthedoor Sep 04 '17 at 23:37
  • You may need to de-indent the line `header-includes` – duckmayr Sep 04 '17 at 23:48
  • I thought you said to get rid of it and just put it under "in header" – wolfsatthedoor Sep 04 '17 at 23:49
  • Yeah, fair enough; I was just looking back over your posted preamble code and noticed it was indented there when it should not have been. I forgot you would have removed that line. – duckmayr Sep 04 '17 at 23:53
  • Based on some things I found by searching for related terms to your error, especially [link](https://github.com/rstudio/packrat/issues/382) and [link](https://github.com/rstudio/packrat/issues/382) (see the last comment), this may be an issue related to RStudio not reading the file encoding correctly, or the inclusion of a non-latin character without UTF-8 encoding, or some combination of those issues. Are there any such characters in your document? What is the encoding your files are saved with? Does pasting the content of your .Rmd and .r files into new files allow you to Knit the document? – duckmayr Sep 05 '17 at 00:38
  • is there not just a way to do this manually after each section change? I do have latex characters in my document. I am outputting the beamer presentation to a pdf – wolfsatthedoor Sep 05 '17 at 17:13
  • Yes, there is. I've updated my answer to include it. – duckmayr Sep 05 '17 at 17:43
  • Oh wow, ok this is great, thank you! I think the four dashes to indicate a new frame was precisely what I was looking for. As a side note, it seems to show all subsections and clutters up the table of contents, do you know the command to just show the main headers? – wolfsatthedoor Sep 05 '17 at 21:52
  • Actually, I figured it out, you separate parameters with a comma, and this works: \tableofcontents[currentsection,hideallsubsections] – wolfsatthedoor Sep 05 '17 at 22:11