用于rmarkdown表的单个单元格中的多行

时间:2014-11-25 07:28:50

标签: r r-markdown

我想创建一个使用RMarkdown在单个单元格中有多行的表。此页面提到多行和网格表格单元格(http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html)。但似乎反斜杠不起作用。

A backslash followed by a newline is also a hard line break. 
Note: in multiline and grid table cells, this is the only way 
to create a hard line break, since trailing spaces in the cells are ignored.

这是我的示例Rmd文件。

---
title: "Test"
author: "test"
date: "Tuesday, November 25, 2014"
output: html_document
---
Line 1 \  Line2  | Line 1 \  Line2
------------- | -------------
Line 1 \  Line2 | Line 1 \  Line2

有可能实现这一目标吗?谢谢你的任何建议。

这是我的sessionInfo

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] digest_0.6.4     htmltools_0.2.6  rmarkdown_0.3.11 tools_3.1.1     

1 个答案:

答案 0 :(得分:2)

绝对可行,请参阅pander.CrossTable使用此方法:

> pander::pander(descr::CrossTable(mtcars$am, mtcars$gear))

----------------------------------------------------------------
   \     mtcars$gear\     \      \       \  
 mtcars$am         3             4           5          Total   
------------ -------------- ----------- ------------ -----------
  **0**\         \       \       \      \   
    N\           15\           4\           0\          19\     
Chi-square\    4.1694\       1.3706\     2.9688\         \      
  Row(%)\     78.9474%\     21.0526%\    0.0000%\    59.3750%\  
Column(%)\    100.0000%\    33.3333%\    0.0000%\         \     
  Total(%)      46.875%       12.500%      0.000%               

  **1**\         \       \       \      \   
    N\            0\           8\           5\          13\     
Chi-square\    6.0938\       2.0032\     4.3389\         \      
  Row(%)\      0.0000%\     61.5385%\   38.4615%\    40.6250%\  
Column(%)\     0.0000%\     66.6667%\   100.0000%\        \     
  Total(%)       0.000%       25.000%     15.625%               

   Total\         15\          12\          5\           32\    
                46.875%        37.5%      15.625%               
----------------------------------------------------------------