6

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?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419

1 Answers1

3

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

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Alright I was attempting to compile a document with class `article` that had alphabetic figure names in the appendix. This is possible with `article` and `html_document2`, but not with `article` and `pdf_document2`. Is there any chance you are looking to include this functionality at some point? – Forrest Williams Nov 18 '16 at 19:20
  • Please see my updated answer at the end. The figure was numbered as 1 instead of A.1, which means the standard `article` class in LaTeX does not support numbering by sections. You have to use other packages. See this post for possible solutions: http://tex.stackexchange.com/q/28333/9128 You will need the `in_header` option in YAML if you want to insert code to the preamble. See http://rmarkdown.rstudio.com/pdf_document_format.html for documentation. – Yihui Xie Nov 18 '16 at 22:42
  • Thank you for all of your help Yuhui! – Forrest Williams Nov 21 '16 at 12:06