问题
I would like to create a table which has multiple lines in a single cell using RMarkdown. This page mentions multiline and grid table cells (http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html). But it seems backslash is not working.
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.
This is my example Rmd file.
---
title: "Test"
author: "test"
date: "Tuesday, November 25, 2014"
output: html_document
---
Line 1 \ Line2 | Line 1 \ Line2
------------- | -------------
Line 1 \ Line2 | Line 1 \ Line2
Is it possible to achieve this? Thanks for any suggestions.
This is my 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:
It's absolutely doable, see eg pander.CrossTable
using this approach:
> 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%
----------------------------------------------------------------
来源:https://stackoverflow.com/questions/27120954/multiple-lines-in-a-single-cell-for-rmarkdown-table