yihui / printr

Some (magical) printing methods for knitr
https://yihui.org/printr/
118 stars 24 forks source link

automatic table numbering does not work for default html format #23

Closed yimingli closed 7 years ago

yimingli commented 7 years ago

Table numbering with table caption works for PDF and html_vignette format, but not for default html format. Also, the table caption is some light grey color, instead of black as in html_vignette format.

yihui commented 7 years ago

Could you provide a minimal, self-contained, and reproducible example?

yimingli commented 7 years ago

Oh, sorry about that. Here it is:

---
title: "Untitled"
output:
    # knitr:::html_vignette
    html_document
---

```{r}
library(printr)

# use the same data used in the printr vignette
set.seed(123)
x = matrix(rnorm(40), 5)
dimnames(x) = list(NULL, head(LETTERS, ncol(x)))

# further customization via kable(), e.g. digits and captions
knitr::kable(x, digits = 2, caption = 'A table produced by printr.')

I also tried to re-knit the `printr` introduction vignette to "normal" html instead of vignette html. The result is less pleasant than the vignette format.

Here is my environment:

sessionInfo()

R version 3.3.1 (2016-06-21)

Platform: x86_64-apple-darwin13.4.0 (64-bit)

Running under: OS X 10.11.6 (El Capitan)

locale:

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:

[1] stats graphics grDevices utils datasets methods base

other attached packages:

[1] printr_0.0.6

loaded via a namespace (and not attached):

[1] magrittr_1.5 assertthat_0.1 tools_3.3.1

[4] htmltools_0.3.5 yaml_2.1.13 tibble_1.2-12

[7] Rcpp_0.12.7 stringi_1.1.2 rmarkdown_1.0.9013

[10] highr_0.6 knitr_1.14.6 stringr_1.1.0.9000

[13] digest_0.6.10 evaluate_0.9

yihui commented 7 years ago

Numbering figures/tables is the default feature of LaTeX. For knitr:::html_vignette, it was implemented via JavaScript: https://github.com/yihui/knitr/blob/master/inst/misc/vignette.html Normally figures/tables won't be numbered in non-LaTeX output. If you want to number them, you may consider the bookdown package. See rstudio/bookdown#190 for more info.

yimingli commented 7 years ago

Thanks. Any idea why the table caption is left aligned and size and color look funny when knitted to an html_document? Is customizing css the only way to adjust it?

yihui commented 7 years ago

Perhaps Bootstrap defined that style for captions. You can certainly use CSS to customize the style.