2017-08-12 25 views
3

當與bookdown :: html_document2一起使用時,pander不包括表格編號。我錯過了一些選擇嗎?在bookdown中沒有表格編號:html_document2

--- 
title: "Pander Table Numbering" 
output: bookdown::html_document2 
--- 

# Chapter 1 

```{r} 
library(knitr) 
library(pander) 
# Table 1.1 
kable(head(iris), caption = "Iris with kable") 
# Another Table 1.1 (ok, same chunk = same table) 
kable(head(mtcars), caption = "Mtcars kable") 
``` 

```{r} 
# No table number 
pander(head(iris), caption = "Iris with pander") 
``` 

```{r} 
# Table 1.2 
kable(head(mtcars), caption = "Mtcars kable") 
``` 
+1

@daroczig太糟糕了,我種種原因錯過了你user2017 –

+1

希望看到你下一次:)關於這個問題,我已經開了[GH票](https://github.com/Rapporter/pander/issues/307),並希望通過一些幫助來解決這個問題。不幸的是,我對'bookdown'內部信息不是很熟悉,但是爲'pander'增加一個新參數可能很容易解決這個問題。 – daroczig

回答

3

https://bookdown.org/yihui/bookdown/tables.html

如果您決定使用其它的R程序包生成的表,你必須確保該表的環境標籤的表格標題的開始出現在形式(\#label) (再次,label必須具有前綴tab:)。

這裏的原因是pander::pander()不會產生正確的(\#tab:***)。您可以將該錯誤報告給作者pander

kable(head(iris), caption = "Iris with kable")

Table: (\#tab:unnamed-chunk-1)Iris with kable 

Sepal.Length Sepal.Width Petal.Length Petal.Width Species 
------------- ------------ ------------- ------------ -------- 
     5.1   3.5   1.4   0.2 setosa 
     4.9   3.0   1.4   0.2 setosa 
     4.7   3.2   1.3   0.2 setosa 
     4.6   3.1   1.5   0.2 setosa 
     5.0   3.6   1.4   0.2 setosa 
     5.4   3.9   1.7   0.4 setosa 

pander(head(iris), caption = "Iris with pander")

------------------------------------------------------------------- 
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 
-------------- ------------- -------------- ------------- --------- 
    5.1   3.5   1.4   0.2  setosa 

    4.9    3   1.4   0.2  setosa 

    4.7   3.2   1.3   0.2  setosa 

    4.6   3.1   1.5   0.2  setosa 

    5    3.6   1.4   0.2  setosa 

    5.4   3.9   1.7   0.4  setosa 
------------------------------------------------------------------- 

Table: Iris with pander 
+0

感謝您在文檔中找到正確的位置。由於軟件包作者@daroczig是最快的SO響應者之一,有時會在幾小時內糾正這些錯誤,所以他可能正在度假。 –