我不明白为什么在使用RStudio中的knitr和markdown包时,无法正确格式化下表示例。在每种情况下,列标题下方的内容都很好,但无论使用何种格式,列标题始终保持对齐。
以下是我的测试.Rmd文件,该文件基于
中Markdown帮助文件中的示例http://pandoc.org/README.html#tables
和
http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#tables
---
output:
html_document
---
# Table tests
## Simple table
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1
## Multiline table
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
## Piped table
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
## cat() table
This is another option that I found [here](https://stackoverflow.com/questions/19997242/simple-manual-rmarkdown-tables-that-look-good-in-html-pdf-and-docx?rq=1), which _should_ work well under many formats .
```{r, echo=FALSE, results='asis'}
tabl <- "
| Tables | Are | Cool |
|---------------|:-------------:|------:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
"
cat(tabl)
```
这是我的sessionInfo
:
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (unknown)
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
loaded via a namespace (and not attached):
[1] htmltools_0.3.5 tools_3.2.0 yaml_2.1.13 Rcpp_0.12.4 rmarkdown_0.9.5 knitr_1.12.3 digest_0.6.9