Rendering Appendix Figure Numbers in Bookdown

风流意气都作罢 提交于 2019-12-23 19:08:29

问题


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?


回答1:


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

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

> 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):



来源:https://stackoverflow.com/questions/40678036/rendering-appendix-figure-numbers-in-bookdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!