0

I don't understand why I can't get the following table examples to format correctly when using the knitr and markdown packages in RStudio. In each case, the content below the column headings is fine, but the column headings are always left aligned no matter what formatting is used.

Here is my test .Rmd file based on the examples from the Markdown help files at

http://pandoc.org/README.html#tables

and

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

Here is my 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

Here is the result of knitting it in RStudio.

Mark S
  • 603
  • 4
  • 9

0 Answers0