2014-11-25 35 views
1

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

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  
+0

我试图从你的链接,多表的例子,它没有工作。好奇。也许需要在YAML头文件中设置一些扩展名? – 2014-11-25 08:53:54

回答

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%    
---------------------------------------------------------------- 
相关问题