Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering Appendix Figure Numbers in Bookdown

Tags:

r

bookdown

Bookdown is a great package and I look forward to seeing how it developes, but right now I am having troubling rendering figure numbers in the pdf_document2 format when figures are in appendices. Specifically when a figure with a caption is in an appendix the figure number should be of the form A.1, A.2, B.1, B.2 etc. but instead the figure numbers are treated as normal sections with numbers 3.1, 3.2, 4.1, 4.2 etc. where the appendices are the third and fourth sections respectively. Here is an example:

---
title: "Untitled"
author: "John Doe"
date: "November 18, 2016"
documentclass: article
output:
  bookdown::pdf_document2:
    toc: yes
    fig_caption: yes
    number_sections: yes
linkcolor: blue
---

# Chapter One

```{r a, fig.cap="rabble rabble"}
plot(cars) # a scatterplot
```

```{r b, fig.cap="rabble rabble"}
plot(cars) # a scatterplot
```

# Chapter Two

# (APPENDIX) Appendix {-}
# Appendix A

```{r c, fig.cap="rabble rabble"}
plot(cars) # a scatterplot
```

# Appendix B

```{r d, fig.cap="rabble rabble"}
plot(cars) # a scatterplot
```

Is this an issue with bookdown itself, or is it incorrect in some way?

like image 631
Forrest Williams Avatar asked Oct 17 '22 22:10

Forrest Williams


1 Answers

I cannot reproduce your issue. When I compile your document, the figures are continuously numbered throughout the document from 1, 2, 3, 4.

figures in an article

If I change the document class from article to book, I get A.1 and B.1 as expected.

figures in a book

> devtools::session_info('bookdown')
Session info --------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.1.2)             
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Chicago             
 date     2016-11-18                  

Packages ------------------------------------------------------------
 package     * version  date       source                            
 ....
 bookdown      0.2.3    2016-11-18 Github (rstudio/bookdown@7c09c9b) 
 ....

A plain-LaTeX example, without using bookdown:

\documentclass{article}

\begin{document}

\section{Test 1}
\section{Test 2}

\appendix

\section{Test 3}

\begin{figure}[h]
\caption{Test caption.}
\end{figure}

\end{document}

Output (the figure was number 1, instead of A.1):

figure in appendix

like image 77
Yihui Xie Avatar answered Oct 21 '22 00:10

Yihui Xie