Search code examples
rmarkdownr-markdownbookdown

How to add list of figures and list of tables to the table of content with R markdown and bookdown


I have a report (pdf output) where I want to add bibliography, list of figures and list of tables to the appendix. And I want those three elements to appear in the table of content.

I add the bibliography by adding bibliography: bibliography.bib to my yaml header. The list of figures and the list of tables I add with LaTex directly.

My appendix therefore looks like:

# Literature {-}

\listoffigures

\listoftables

This nearly works: bibliography, list of figures and list of tables are rendered correctly.

The only problem is, the table of content does only show an entry Literature. The list of figures and list of tables does not appear.

How can I fix this?


I tried with lof: yes and lot: yes in various places of the yaml header (idea from here as well as with toc_appendix: yes (from the same source)

What am I missing?


My complete header looks like:

---
title: something
header-includes: \usepackage{graphicx} \usepackage{float} \usepackage{xcolor} \usepackage{framed} \usepackage{longtable} \definecolor{shadecolor}{RGB}{240,240,240} \pagenumbering{roman} \usepackage{caption} \captionsetup{font=footnotesize}
output:
  bookdown::pdf_book:
    fig_caption: yes
    highlight: kate
    number_sections: yes
    toc: yes
date: | 
    |  
    | `r format(Sys.time(), '%B %d, %Y')`
documentclass: report
geometry: margin=1in
fontfamily: mathpazo
fontsize: 11pt
bibliography: bibliography.bib
preamble: |
  % Any extra latex you need in the preamble
---

Solution

  • The problem lies with the document class report. I guess that it does not handle the list of tables or list of figures like the article class does.

    A simple solution is to add \usepackage[nottoc]{tocbibind} to your document. The package does exactly what you want - it adds both appendix sections to your table of contents. You still have to manually add them at the end of your document using \listoffigures and \listoftables.